當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。