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


Java NominalMapping类代码示例

本文整理汇总了Java中com.rapidminer.example.table.NominalMapping的典型用法代码示例。如果您正苦于以下问题:Java NominalMapping类的具体用法?Java NominalMapping怎么用?Java NominalMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: learn

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public Model learn(ExampleSet exampleSet) throws OperatorException {
	int numberOfNumericalAttributes = 0;
	for (Attribute attribute : exampleSet.getAttributes()) {
		this.checkForStop();
		if (attribute.isNumerical()) {
			numberOfNumericalAttributes++;
		}
	}

	NominalMapping labelMapping = exampleSet.getAttributes().getLabel().getMapping();
	String[] labelValues = new String[labelMapping.size()];
	for (int i = 0; i < labelMapping.size(); i++) {
		this.checkForStop();
		labelValues[i] = labelMapping.mapIndex(i);
	}

	Matrix[] meanVectors = getMeanVectors(exampleSet, numberOfNumericalAttributes, labelValues);
	Matrix[] inverseCovariance = getInverseCovarianceMatrices(exampleSet, labelValues);

	return getModel(exampleSet, labelValues, meanVectors, inverseCovariance,
			getAprioriProbabilities(exampleSet, labelValues));
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:24,代码来源:LinearDiscriminantAnalysis.java

示例2: createPreprocessingModel

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public PreprocessingModel createPreprocessingModel(ExampleSet exampleSet) throws OperatorException {
	boolean sortMappings = getParameterAsBoolean(PARAMETER_SORT_MAPPING_ALPHABETICALLY);

	Map<String, MappingTranslation> translations = new HashMap<String, MappingTranslation>();

	exampleSet.recalculateAllAttributeStatistics();
	for (Attribute attribute : exampleSet.getAttributes()) {
		MappingTranslation translation = new MappingTranslation((NominalMapping) attribute.getMapping().clone());
		if (attribute.isNominal()) {
			for (String value : attribute.getMapping().getValues()) {
				double count = exampleSet.getStatistics(attribute, Statistics.COUNT, value);
				if (count > 0) {
					translation.newMapping.mapString(value);
				}
			}
			if (translation.newMapping.size() < attribute.getMapping().size()) {
				if (sortMappings) {
					translation.newMapping.sortMappings();
				}
				translations.put(attribute.getName(), translation);
			}
		}
	}
	return new RemoveUnusedNominalValuesModel(exampleSet, translations);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:27,代码来源:RemoveUnusedNominalValuesOperator.java

示例3: apply

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
	if (exampleSet.getAttributes().getWeight() == null) {
		Attribute weight = AttributeFactory.createAttribute(Attributes.WEIGHT_NAME, Ontology.NUMERICAL);
		exampleSet.getExampleTable().addAttribute(weight);
		exampleSet.getAttributes().addRegular(weight);
		exampleSet.getAttributes().setWeight(weight);

		Attribute label = exampleSet.getAttributes().getLabel();
		exampleSet.recalculateAttributeStatistics(label);
		NominalMapping labelMapping = label.getMapping();
		Map<String, Double> labelFrequencies = new HashMap<String, Double>();
		for (String labelName : labelMapping.getValues()) {
			labelFrequencies.put(labelName, exampleSet.getStatistics(label, Statistics.COUNT, labelName));
		}
		double numberOfLabels = labelFrequencies.size();
		double perLabelWeight = getParameterAsDouble(PARAMETER_TOTAL_WEIGHT) / numberOfLabels;
		for (Example example : exampleSet) {
			double exampleWeight = perLabelWeight
					/ labelFrequencies.get(labelMapping.mapIndex((int) example.getValue(label)));
			example.setValue(weight, exampleWeight);
		}
	}
	return exampleSet;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:26,代码来源:EqualLabelWeighting.java

示例4: registerAllCombinationsRecursion

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
/**
 * The recursively called method.
 *
 * @throws UserError
 */
private void registerAllCombinationsRecursion(Attribute[] groupByAttributes,
		MultidimensionalArraySet<AggregationFunction[]> functionSet, boolean ignoreMissings,
		AggregationAttribute[] aggregationAttributes, int[] indices, int depth) throws UserError {
	if (depth == indices.length) {
		AggregationFunction[] functions = new AggregationFunction[aggregationAttributes.length];
		for (int j = 0; j < aggregationAttributes.length; j++) {
			functions[j] = getAggregationFunction(aggregationAttributes[j].functionName, ignoreMissings,
					aggregationAttributes[j].attribute);
		}
		functionSet.set(indices, functions);
	} else {
		NominalMapping mapping = groupByAttributes[depth].getMapping();
		for (String value : mapping.getValues()) {
			indices[depth] = mapping.getIndex(value);
			registerAllCombinationsRecursion(groupByAttributes, functionSet, ignoreMissings, aggregationAttributes,
					indices, depth + 1);
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:25,代码来源:AggregationOperator.java

示例5: getClusterAssignments

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
/**
 * This method returns an array with the indices or the cluster for all examples in the set.
 * This will work with new examples, if centroid based clustering has been used before.
 * Otherwise new examples cannot be assigned.
 */
public int[] getClusterAssignments(ExampleSet exampleSet) {
	int[] clusterAssignments = new int[exampleSet.size()];
	Attribute idAttribute = exampleSet.getAttributes().getId();
	NominalMapping mapping = null;
	if (idAttribute.isNominal()) {
		mapping = idAttribute.getMapping();
	}
	int j = 0;
	for (Example example : exampleSet) {
		double value = example.getValue(idAttribute);
		clusterAssignments[j] = getClusterIndexOfId(mapping != null ? mapping.mapIndex((int) value) : value);
		j++;
	}
	return clusterAssignments;
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:21,代码来源:ClusterModel.java

示例6: learn

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public Model learn(ExampleSet exampleSet) throws OperatorException {
	int numberOfNumericalAttributes = 0;
	for (Attribute attribute : exampleSet.getAttributes()) {
		this.checkForStop();
		if (attribute.isNumerical()) {
			numberOfNumericalAttributes++;
		}
	}

	NominalMapping labelMapping = exampleSet.getAttributes().getLabel().getMapping();
	String[] labelValues = new String[labelMapping.size()];
	for (int i = 0; i < labelMapping.size(); i++) {
		this.checkForStop();
		labelValues[i] = labelMapping.mapIndex(i);
	}

	Matrix[] meanVectors = getMeanVectors(exampleSet, numberOfNumericalAttributes, labelValues);
	Matrix[] inverseCovariance = getInverseCovarianceMatrices(exampleSet, labelValues);

	return getModel(exampleSet, labelValues, meanVectors, inverseCovariance);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:23,代码来源:RegularizedDiscriminantAnalysis.java

示例7: learn

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
public Model learn(ExampleSet exampleSet) throws OperatorException {
	int numberOfNumericalAttributes = 0;
	for (Attribute attribute: exampleSet.getAttributes()) {
		if (attribute.isNumerical()) {
			numberOfNumericalAttributes++;	
		}
	}

	NominalMapping labelMapping = exampleSet.getAttributes().getLabel().getMapping();
	String[] labelValues = new String[labelMapping.size()];
	for (int i = 0; i < labelMapping.size(); i++) {
		labelValues[i] = labelMapping.mapIndex(i);	
	}


	Matrix[] meanVectors = getMeanVectors(exampleSet, numberOfNumericalAttributes, labelValues);
	Matrix[] inverseCovariance = getInverseCovarianceMatrices(exampleSet, labelValues);

	return getModel(exampleSet, labelValues, meanVectors, inverseCovariance, getAprioriProbabilities(exampleSet, labelValues));
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:21,代码来源:LinearDiscriminantAnalysis.java

示例8: createPreprocessingModel

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public PreprocessingModel createPreprocessingModel(ExampleSet exampleSet) throws OperatorException {
    boolean sortMappings = getParameterAsBoolean(PARAMETER_SORT_MAPPING_ALPHABETICALLY);

    Map<String, MappingTranslation> translations = new HashMap<String, MappingTranslation>();

    exampleSet.recalculateAllAttributeStatistics();
    for (Attribute attribute: exampleSet.getAttributes()) {
        MappingTranslation translation = new MappingTranslation((NominalMapping)attribute.getMapping().clone());
        if (attribute.isNominal()) {
            for (String value: attribute.getMapping().getValues()) {
                double count = exampleSet.getStatistics(attribute, Statistics.COUNT, value);
                if (count > 0) {
                    translation.newMapping.mapString(value);
                }
            }
            if (translation.newMapping.size() < attribute.getMapping().size()) {
                if (sortMappings)
                    translation.newMapping.sortMappings();
                translations.put(attribute.getName(), translation);
            }
        }
    }
    return new RemoveUnusedNominalValuesModel(exampleSet, translations);
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:26,代码来源:RemoveUnusedNominalValuesOperator.java

示例9: apply

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {		 
	if (exampleSet.getAttributes().getWeight() == null) {			
		Attribute weight = AttributeFactory.createAttribute(Attributes.WEIGHT_NAME, Ontology.NUMERICAL);
		exampleSet.getExampleTable().addAttribute(weight);
		exampleSet.getAttributes().addRegular(weight);
		exampleSet.getAttributes().setWeight(weight);

		Attribute label = exampleSet.getAttributes().getLabel();
		exampleSet.recalculateAttributeStatistics(label);
		NominalMapping labelMapping = label.getMapping();
		Map<String, Double> labelFrequencies = new HashMap<String, Double>();
		for (String labelName: labelMapping.getValues()) {
			labelFrequencies.put(labelName, exampleSet.getStatistics(label, Statistics.COUNT, labelName));			
		}
		double numberOfLabels = labelFrequencies.size();
		double perLabelWeight = getParameterAsDouble(PARAMETER_TOTAL_WEIGHT) / numberOfLabels;
		for (Example example: exampleSet) {
			double exampleWeight = perLabelWeight / labelFrequencies.get(labelMapping.mapIndex((int)example.getValue(label)));
			example.setValue(weight, exampleWeight);
		}
	}
	return exampleSet;
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:25,代码来源:EqualLabelWeighting.java

示例10: registerAllCombinationsRecursion

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
/**
 * The recursively called method.
 * 
 * @throws UserError
 */
private void registerAllCombinationsRecursion(Attribute[] groupByAttributes, MultidimensionalArraySet<AggregationFunction[]> functionSet, boolean ignoreMissings, AggregationAttribute[] aggregationAttributes, int[] indices, int depth) throws UserError {
    if (depth == indices.length) {
        AggregationFunction[] functions = new AggregationFunction[aggregationAttributes.length];
        for (int j = 0; j < aggregationAttributes.length; j++) {
            functions[j] = getAggregationFunction(aggregationAttributes[j].functionName, ignoreMissings, aggregationAttributes[j].attribute);
        }
        functionSet.set(indices, functions);
    } else {
        NominalMapping mapping = groupByAttributes[depth].getMapping();
        for (String value : mapping.getValues()) {
            indices[depth] = mapping.getIndex(value);
            registerAllCombinationsRecursion(groupByAttributes, functionSet, ignoreMissings, aggregationAttributes, indices, depth + 1);
        }
    }
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:21,代码来源:AggregationOperator.java

示例11: SimilarityExampleSet

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
public SimilarityExampleSet(ExampleSet parent, DistanceMeasure measure) {
	this.parent = parent;

	this.parentIdAttribute = parent.getAttributes().getId();
	this.attributes = new SimpleAttributes();

	Attribute firstIdAttribute = null;
	Attribute secondIdAttribute = null;
	firstIdAttribute = AttributeFactory.createAttribute("FIRST_ID", this.parentIdAttribute.getValueType());
	secondIdAttribute = AttributeFactory.createAttribute("SECOND_ID", this.parentIdAttribute.getValueType());

	this.attributes.addRegular(firstIdAttribute);
	this.attributes.addRegular(secondIdAttribute);
	firstIdAttribute.setTableIndex(0);
	secondIdAttribute.setTableIndex(1);

	// copying mapping of original id attribute
	if (parentIdAttribute.isNominal()) {
		NominalMapping mapping = parentIdAttribute.getMapping();
		firstIdAttribute.setMapping((NominalMapping) mapping.clone());
		secondIdAttribute.setMapping((NominalMapping) mapping.clone());
	}

	String name = "SIMILARITY";
	if (measure.isDistance()) {
		name = "DISTANCE";
	}

	Attribute similarityAttribute = AttributeFactory.createAttribute(name, Ontology.REAL);
	this.attributes.addRegular(similarityAttribute);
	similarityAttribute.setTableIndex(2);

	this.measure = measure;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:35,代码来源:SimilarityExampleSet.java

示例12: replaceValue

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
/**
 * Replaces the given real value by the new one. Please note that this method will only work for
 * nominal attributes.
 */
public static void replaceValue(Attribute attribute, String oldValue, String newValue) {
	if (!attribute.isNominal()) {
		throw new RuntimeException("Example-Tools: replaceValue is only supported for nominal attributes.");
	}
	NominalMapping mapping = attribute.getMapping();
	int oldIndex = mapping.getIndex(oldValue);
	if (oldIndex < 0) {
		throw new RuntimeException(
				"Example-Tools: replaceValue cannot be performed since old value was not defined in the attribute.");
	}
	mapping.setMapping(newValue, oldIndex);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:17,代码来源:Tools.java

示例13: isNominalMappingSubsetOrEqualTo

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
/**
 * Check if the childMapping is a subset of the superMapping or equal to it.
 *
 * @param childMapping
 *            the potential subset you want to check
 * @param superMapping
 *            the {@link NominalMapping} you want to check against
 * @return will return true if the {@link NominalMapping} is a subset or equal else false will
 *         be returned
 */
public static boolean isNominalMappingSubsetOrEqualTo(NominalMapping childMapping, NominalMapping superMapping) {
	if (childMapping.size() > superMapping.size()) {
		return false;
	}
	List<String> superList = superMapping.getValues();
	for (String value : childMapping.getValues()) {
		if (!superList.contains(value)) {
			return false;
		}
	}
	return true;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:Tools.java

示例14: assertEquals

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
/**
 * Tests two nominal mappings for its size and values.
 *
 * @param message
 *            message to display if an error occurs
 * @param expected
 *            expected value
 * @param actual
 *            actual value
 * @param ignoreOrder
 *            if <code>true</code> the order of the mappings is not checked, but only the size
 *            of the mapping and that all values of <code>expected</code> are present in
 *            <code>actual</code>.
 */
public static void assertEquals(String message, NominalMapping expected, NominalMapping actual, boolean ignoreOrder) {
	if (expected == actual) {
		return;
	}
	Assert.assertTrue(expected == null && actual == null || expected != null && actual != null);
	if (expected == null || actual == null) {
		return;
	}

	Assert.assertEquals(message + " (nominal mapping size)", expected.size(), actual.size());

	List<String> expectedValues = expected.getValues();
	List<String> actualValues = actual.getValues();

	// check that we have the same values in both mappings:
	Set<String> expectedValuesSet = new HashSet<String>(expectedValues);
	Set<String> actualValuesSet = new HashSet<String>(actualValues);
	Assert.assertEquals(message + " (different nominal values)", expectedValuesSet, actualValuesSet);

	if (!ignoreOrder) {
		// check order

		Iterator<String> expectedIt = expectedValues.iterator();
		while (expectedIt.hasNext()) {
			String expectedValue = expectedIt.next();
			Assert.assertEquals(message + " (index of nominal value '" + expectedValue + "')",
					expected.mapString(expectedValue), actual.mapString(expectedValue));
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:45,代码来源:RapidAssert.java

示例15: doWork

import com.rapidminer.example.table.NominalMapping; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
	CentroidClusterModel model = modelInput.getData(CentroidClusterModel.class);

	Attributes trainAttributes = model.getTrainingHeader().getAttributes();
	String[] attributeNames = model.getAttributeNames();
	Attribute[] attributes = new Attribute[attributeNames.length + 1];

	// init operator progress
	getProgress().setTotal(model.getNumberOfClusters() + attributeNames.length);

	for (int i = 0; i < attributeNames.length; i++) {
		Attribute originalAttribute = trainAttributes.get(attributeNames[i]);
		attributes[i] = AttributeFactory.createAttribute(attributeNames[i], originalAttribute.getValueType());
		if (originalAttribute.isNominal()) {
			attributes[i].setMapping((NominalMapping) originalAttribute.getMapping().clone());
		}
		getProgress().step();
	}
	Attribute clusterAttribute = AttributeFactory.createAttribute("cluster", Ontology.NOMINAL);
	attributes[attributes.length - 1] = clusterAttribute;

	MemoryExampleTable table = new MemoryExampleTable(attributes);
	for (int i = 0; i < model.getNumberOfClusters(); i++) {
		double[] data = new double[attributeNames.length + 1];
		System.arraycopy(model.getCentroidCoordinates(i), 0, data, 0, attributeNames.length);
		data[attributeNames.length] = clusterAttribute.getMapping().mapString("cluster_" + i);
		table.addDataRow(new DoubleArrayDataRow(data));
		getProgress().step();
	}

	ExampleSet resultSet = table.createExampleSet();
	resultSet.getAttributes().setSpecialAttribute(clusterAttribute, Attributes.CLUSTER_NAME);

	getProgress().complete();

	modelOutput.deliver(model);
	exampleSetOutput.deliver(resultSet);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:40,代码来源:ExtractClusterPrototypes.java


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