当前位置: 首页>>代码示例>>Java>>正文


Java Tools.hasNominalLabels方法代码示例

本文整理汇总了Java中com.rapidminer.example.Tools.hasNominalLabels方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.hasNominalLabels方法的具体用法?Java Tools.hasNominalLabels怎么用?Java Tools.hasNominalLabels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rapidminer.example.Tools的用法示例。


在下文中一共展示了Tools.hasNominalLabels方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculateWeights

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected AttributeWeights calculateWeights(ExampleSet exampleSet) throws OperatorException {
	Tools.hasNominalLabels(exampleSet, getOperatorClassName());
	Attribute label = exampleSet.getAttributes().getLabel();

	// discretize numerical data
	BinDiscretization discretization = null;
	try {
		discretization = OperatorService.createOperator(BinDiscretization.class);
	} catch (OperatorCreationException e) {
		throw new UserError(this, 904, "Discretization", e.getMessage());
	}

	int numberOfBins = getParameterAsInt(BinDiscretization.PARAMETER_NUMBER_OF_BINS);
	discretization.setParameter(BinDiscretization.PARAMETER_NUMBER_OF_BINS, numberOfBins + "");
	exampleSet = discretization.doWork(exampleSet);

	// create and deliver weights
	double totalProgress = exampleSet.getAttributes().size() * exampleSet.size();
	long progressCounter = 0;
	getProgress().setTotal(100);
	AttributeWeights weights = new AttributeWeights(exampleSet);
	for (Attribute attribute : exampleSet.getAttributes()) {
		double[][] counters = new double[attribute.getMapping().size()][label.getMapping().size()];
		for (Example example : exampleSet) {
			counters[(int) example.getValue(attribute)][(int) example.getLabel()]++;
			if (++progressCounter % PROGRESS_UPDATE_STEPS == 0) {
				getProgress().setCompleted((int) (100 * (progressCounter / totalProgress)));
			}
		}
		double weight = ContingencyTableTools.symmetricalUncertainty(counters);
		weights.setWeight(attribute.getName(), weight);
	}

	return weights;
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:37,代码来源:SymmetricalUncertaintyOperator.java

示例2: doWork

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
	Tools.hasNominalLabels(exampleSet, getOperatorClassName());
	List<String[]> rankings = getParameterList(PARAMETER_RANKING_COSTS);
	int i = 0;
	double[] costs = new double[rankings.size()];
	int[] indices = new int[rankings.size()];
	for (String[] pair : rankings) {
		indices[i] = Integer.valueOf(pair[0]);
		costs[i] = Double.valueOf(pair[1]);
		// TODO: Check if correctly sorted or sort automatically
		i++;
	}

	MeasuredPerformance criterion = new RankingCriterion(indices, costs, exampleSet);
	performance = new PerformanceVector();
	performance.addCriterion(criterion);
	// now measuring costs
	criterion.startCounting(exampleSet, false);
	for (Example example : exampleSet) {
		criterion.countExample(example);
	}

	exampleSetOutput.deliver(exampleSet);
	performanceOutput.deliver(performance);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:28,代码来源:RankingEvaluator.java

示例3: checkCompatibility

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected void checkCompatibility(ExampleSet exampleSet) throws OperatorException {
	Tools.isNonEmpty(exampleSet);
	Tools.hasNominalLabels(exampleSet, "the calculation of performance criteria for binominal classification tasks");

	Attribute label = exampleSet.getAttributes().getLabel();
	if (label.getMapping().size() != 2) {
		throw new UserError(this, 114, "the calculation of performance criteria for binominal classification tasks",
				label.getName());
	}
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:12,代码来源:BinominalClassificationPerformanceEvaluator.java

示例4: doWork

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
	Tools.hasNominalLabels(exampleSet, getOperatorClassName());
	Attribute label = exampleSet.getAttributes().getLabel();
	if (label.getMapping().size() != 2) {
		throw new UserError(this, 114, "ROC Charts", label);
	}

	if (exampleSet.getAttributes().getPredictedLabel() != null && getParameterAsBoolean(PARAMETER_USE_MODEL)) {
		getLogger().warning("Input example already has a predicted label which will be removed.");
		PredictionModel.removePredictedLabel(exampleSet);
	}
	if (exampleSet.getAttributes().getPredictedLabel() == null && !getParameterAsBoolean(PARAMETER_USE_MODEL)) {
		throw new UserError(this, 107);
	}
	Model model = null;
	if (getParameterAsBoolean(PARAMETER_USE_MODEL)) {
		model = modelInput.getData(Model.class);
		exampleSet = model.apply(exampleSet);
	}
	if (exampleSet.getAttributes().getPredictedLabel() == null) {
		throw new UserError(this, 107);
	}

	ROCDataGenerator rocDataGenerator = new ROCDataGenerator(1.0d, 1.0d);
	ROCData rocPoints = rocDataGenerator.createROCData(exampleSet, getParameterAsBoolean(PARAMETER_USE_EXAMPLE_WEIGHTS),
			ROCBias.getROCBiasParameter(this));
	rocDataGenerator.createROCPlotDialog(rocPoints);

	PredictionModel.removePredictedLabel(exampleSet);

	modelOutput.deliver(model);
	exampleSetOutput.deliver(exampleSet);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:36,代码来源:ROCChartGenerator.java

示例5: doWork

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
	Model model = modelInput.getData(Model.class);

	Tools.hasNominalLabels(exampleSet, getOperatorClassName());
	Attribute label = exampleSet.getAttributes().getLabel();
	if (label.getMapping().size() != 2) {
		throw new UserError(this, 114, getOperatorClassName(), label);
	}

	ExampleSet workingSet = (ExampleSet) exampleSet.clone();
	if (workingSet.getAttributes().getPredictedLabel() != null) {
		PredictionModel.removePredictedLabel(workingSet);
	}

	workingSet = model.apply(workingSet);
	if (workingSet.getAttributes().getPredictedLabel() == null) {
		throw new UserError(this, 107);
	}

	LiftDataGenerator liftDataGenerator = new LiftDataGenerator();
	List<double[]> liftPoints = liftDataGenerator.createLiftDataList(workingSet);
	liftDataGenerator.createLiftChartPlot(liftPoints);

	PredictionModel.removePredictedLabel(workingSet);

	exampleSetOutput.deliver(exampleSet);
	modelOutput.deliver(model);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:31,代码来源:LiftChartGenerator.java

示例6: doWork

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	// sanity checks
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);

	// checking preconditions
	Tools.hasNominalLabels(exampleSet, getOperatorClassName());
	Attribute label = exampleSet.getAttributes().getLabel();
	exampleSet.recalculateAttributeStatistics(label);
	NominalMapping mapping = label.getMapping();
	if (mapping.size() != 2) {
		throw new UserError(this, 118, label, Integer.valueOf(mapping.getValues().size()), Integer.valueOf(2));
	}
	if (exampleSet.getAttributes().getPredictedLabel() == null) {
		throw new UserError(this, 107);
	}
	boolean useExplictLabels = getParameterAsBoolean(PARAMETER_DEFINE_LABELS);

	double secondCost = getParameterAsDouble(PARAMETER_MISCLASSIFICATION_COSTS_SECOND);
	double firstCost = getParameterAsDouble(PARAMETER_MISCLASSIFICATION_COSTS_FIRST);
	if (useExplictLabels) {
		String firstLabel = getParameterAsString(PARAMETER_FIRST_LABEL);
		String secondLabel = getParameterAsString(PARAMETER_SECOND_LABEL);

		if (mapping.getIndex(firstLabel) == -1) {
			throw new UserError(this, 143, firstLabel, label.getName());
		}
		if (mapping.getIndex(secondLabel) == -1) {
			throw new UserError(this, 143, secondLabel, label.getName());
		}

		// if explicit order differs from order in data: internally swap costs.
		if (mapping.getIndex(firstLabel) > mapping.getIndex(secondLabel)) {
			double temp = firstCost;
			firstCost = secondCost;
			secondCost = temp;
		}
	}

	// check whether the confidence attributes are available
	if (exampleSet.getAttributes().getConfidence(mapping.getPositiveString()) == null) {
		throw new UserError(this, 113, Attributes.CONFIDENCE_NAME + "_" + mapping.getPositiveString());
	}
	if (exampleSet.getAttributes().getConfidence(mapping.getNegativeString()) == null) {
		throw new UserError(this, 113, Attributes.CONFIDENCE_NAME + "_" + mapping.getNegativeString());
	}
	// create ROC data
	ROCDataGenerator rocDataGenerator = new ROCDataGenerator(firstCost, secondCost);
	ROCData rocData = rocDataGenerator.createROCData(exampleSet, getParameterAsBoolean(PARAMETER_USE_EXAMPLE_WEIGHTS),
			ROCBias.getROCBiasParameter(this));

	// create plotter
	if (getParameterAsBoolean(PARAMETER_SHOW_ROC_PLOT)) {
		rocDataGenerator.createROCPlotDialog(rocData, true, true);
	}

	// create and return output
	exampleSetOutput.deliver(exampleSet);
	thresholdOutput.deliver(new Threshold(rocDataGenerator.getBestThreshold(), mapping.getNegativeString(), mapping
			.getPositiveString()));
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:62,代码来源:ThresholdFinder.java

示例7: checkCompatibility

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected void checkCompatibility(ExampleSet exampleSet) throws OperatorException {
	Tools.isNonEmpty(exampleSet);
	Tools.hasNominalLabels(exampleSet, "the calculation of performance criteria for classification tasks");
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:6,代码来源:PolynominalClassificationPerformanceEvaluator.java

示例8: doWork

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
	Tools.hasNominalLabels(exampleSet, getOperatorClassName());
	Attribute predictedLabel = exampleSet.getAttributes().getPredictedLabel();
	if (predictedLabel == null) {
		throw new UserError(this, 107);
	}
	Attribute label = exampleSet.getAttributes().getLabel();
	double[][] costMatrix = getParameterAsMatrix(PARAMETER_COST_MATRIX);

	// build label ordering map
	Map<String, Integer> classOrderMap = null;
	if (isParameterSet(PARAMETER_CLASS_DEFINITION)) {
		String[] enumeratedValues = ParameterTypeEnumeration
				.transformString2Enumeration(getParameterAsString(PARAMETER_CLASS_DEFINITION));

		if (enumeratedValues.length > 0) {
			classOrderMap = new HashMap<String, Integer>();
			int i = 0;

			for (String className : enumeratedValues) {
				classOrderMap.put(className, i);
				i++;
			}
			// check whether each possible label occurred once
			for (String value : label.getMapping().getValues()) {
				if (!classOrderMap.containsKey(value)) {
					throw new UserError(this, "performance_costs.class_order_definition_misses_value", value);
				}
			}

			// check whether map is of same size than costMatrix
			if (costMatrix.length != classOrderMap.size()) {
				throw new UserError(this, "performance_costs.cost_matrix_with_wrong_dimension", costMatrix.length,
						classOrderMap.size());
			}

		}
	}

	MeasuredPerformance criterion = new ClassificationCostCriterion(costMatrix, classOrderMap, label, predictedLabel);
	PerformanceVector performance = new PerformanceVector();
	performance.addCriterion(criterion);
	// now measuring costs
	criterion.startCounting(exampleSet, false);
	for (Example example : exampleSet) {
		criterion.countExample(example);
	}

	// setting logging value
	lastCosts = criterion.getAverage();

	exampleSetOutput.deliver(exampleSet);
	performanceOutput.deliver(performance);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:57,代码来源:CostEvaluator.java

示例9: createSVM

import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public SVMInterface createSVM(Attribute label, Kernel kernel, SVMExamples sVMExamples,
		com.rapidminer.example.ExampleSet rapidMinerExamples) throws OperatorException {
	Tools.hasNominalLabels(rapidMinerExamples, "MyKLR");
	return new KLR(this);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:7,代码来源:MyKLRLearner.java


注:本文中的com.rapidminer.example.Tools.hasNominalLabels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。