本文整理汇总了Java中com.rapidminer.example.table.NominalMapping.getValues方法的典型用法代码示例。如果您正苦于以下问题:Java NominalMapping.getValues方法的具体用法?Java NominalMapping.getValues怎么用?Java NominalMapping.getValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapidminer.example.table.NominalMapping
的用法示例。
在下文中一共展示了NominalMapping.getValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例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;
}
示例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);
}
}
}
示例5: 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;
}
示例6: 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));
}
}
}
示例7: SimpleVoteModel
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
public SimpleVoteModel(ExampleSet exampleSet, List<? extends SimplePredictionModel> baseModels) {
super(exampleSet, ExampleSetUtilities.SetsCompareOption.EQUAL,
ExampleSetUtilities.TypesCompareOption.ALLOW_SAME_PARENTS);
this.baseModels = baseModels;
labelIsNominal = getLabel().isNominal();
if (labelIsNominal) {
labelIndices = new LinkedList<>();
NominalMapping mapping = getLabel().getMapping();
List<String> mappingValues = mapping.getValues();
for (String value : mappingValues) {
double index = mapping.getIndex(value);
labelIndices.add(index);
}
}
}
示例8: remap
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
private void remap(Attributes attributes) {
for (String attributeName : affectedAttributeNames) {
Attribute attr = attributes.get(attributeName);
if (attr.isNominal()) {
NominalMapping mapping = attr.getMapping();
List<String> mappingValues = mapping.getValues();
for (String string : mappingValues) {
String replacement = replace(string);
int oldRepr = mapping.getIndex(string);
// Nothing to replace
if (replacement.equals(string)) {
continue;
}
// Replacement already present in mapping -> Replace in example set
else if (mappingValues.contains(replacement)) {
for (Example example : exampleSet) {
double oldValue = example.getValue(attr);
if (Tools.isEqual(oldRepr, oldValue)) {
int newRepr = mapping.getIndex(replacement);
example.setValue(attr, newRepr);
}
}
}
// Replacement not present in mapping -> Replace in mapping
else {
mapping.setMapping(replacement, oldRepr);
}
}
}
}
}
示例9: createCommonMapping
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
private void createCommonMapping(Attribute attribute1, Attribute attribute2, int attributeIndex) {
Map<Double, Double> indexMap1 = new HashMap<Double, Double>();
Map<Double, Double> indexMap2 = new HashMap<Double, Double>();
indexMappingSet1.put(attributeIndex, indexMap1);
indexMappingSet2.put(attributeIndex, indexMap2);
NominalMapping mappingAttr1 = attribute1.getMapping();
NominalMapping mappingAttr2 = attribute2.getMapping();
Set<String> values = new HashSet<String>(mappingAttr1.getValues());
values.addAll(mappingAttr2.getValues());
int index = 0;
for (String value : values) {
int valueIndexAttr1 = mappingAttr1.getIndex(value);
int valueIndexAttr2 = mappingAttr2.getIndex(value);
// Both attributes have a mapping for this value
if (valueIndexAttr1 != -1 && valueIndexAttr2 != -1) {
indexMap1.put((double) valueIndexAttr1, (double) index);
indexMap2.put((double) valueIndexAttr2, (double) index);
index++;
}
}
}
示例10: 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));
}
}
}
示例11: SimpleVoteModel
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
public SimpleVoteModel(ExampleSet exampleSet, List<? extends SimplePredictionModel> baseModels) {
super(exampleSet);
this.baseModels = baseModels;
labelIsNominal = getLabel().isNominal();
if (labelIsNominal) {
labelIndices = new LinkedList<Double>();
NominalMapping mapping = getLabel().getMapping();
List<String> mappingValues = mapping.getValues();
for (String value : mappingValues) {
double index = mapping.getIndex(value);
labelIndices.add(index);
}
}
}
示例12: remap
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
private void remap(Attributes attributes) {
for (String attributeName: affectedAttributeNames) {
Attribute attr = attributes.get(attributeName);
if (attr.isNominal()) {
NominalMapping mapping = attr.getMapping();
for (String string : mapping.getValues()) {
int index = mapping.getIndex(string);
mapping.setMapping(replace(string), index);
}
}
}
}
示例13: createCommonMapping
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
private void createCommonMapping(Attribute attribute1, Attribute attribute2, int attributeIndex) {
Map<Double, Double> indexMap1 = new HashMap<Double, Double>();
Map<Double, Double> indexMap2 = new HashMap<Double, Double>();
indexMappingSet1.put(attributeIndex, indexMap1);
indexMappingSet2.put(attributeIndex, indexMap2);
NominalMapping mappingAttr1 = attribute1.getMapping();
NominalMapping mappingAttr2 = attribute2.getMapping();
Set<String> values = new HashSet<String>(mappingAttr1.getValues());
values.addAll(mappingAttr2.getValues());
int index = 0;
for (String value : values) {
int valueIndexAttr1 = mappingAttr1.getIndex(value);
int valueIndexAttr2 = mappingAttr2.getIndex(value);
// Both attributes have a mapping for this value
if (valueIndexAttr1!=-1 && valueIndexAttr2!=-1) {
indexMap1.put((double)valueIndexAttr1, (double)index);
indexMap2.put((double)valueIndexAttr2, (double)index);
index++;
}
}
}
示例14: apply
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
// searching confidence attributes
Attributes attributes = exampleSet.getAttributes();
Attribute predictedLabel = attributes.getPredictedLabel();
if (predictedLabel == null) {
throw new UserError(this, 107);
}
NominalMapping mapping = predictedLabel.getMapping();
int numberOfLabels = mapping.size();
Attribute[] confidences = new Attribute[numberOfLabels];
String[] labelValue = new String[numberOfLabels];
int i = 0;
for (String value : mapping.getValues()) {
labelValue[i] = value;
confidences[i] = attributes.getConfidence(value);
if (confidences[i] == null) {
throw new UserError(this, 154, value);
}
i++;
}
// generating new prediction attributes
int k = Math.min(numberOfLabels, getParameterAsInt(PARAMETER_NUMBER_OF_RANKS));
Attribute[] kthPredictions = new Attribute[k];
Attribute[] kthConfidences = new Attribute[k];
for (i = 0; i < k; i++) {
kthPredictions[i] = AttributeFactory.createAttribute(predictedLabel.getValueType());
kthPredictions[i].setName(predictedLabel.getName() + "_" + (i + 1));
kthPredictions[i].setMapping((NominalMapping) predictedLabel.getMapping().clone());
kthConfidences[i] = AttributeFactory.createAttribute(Ontology.REAL);
kthConfidences[i].setName(Attributes.CONFIDENCE_NAME + "_" + (i + 1));
attributes.addRegular(kthPredictions[i]);
attributes.addRegular(kthConfidences[i]);
attributes.setSpecialAttribute(kthPredictions[i], Attributes.PREDICTION_NAME + "_" + (i + 1));
attributes.setSpecialAttribute(kthConfidences[i], Attributes.CONFIDENCE_NAME + "_" + (i + 1));
}
exampleSet.getExampleTable().addAttributes(Arrays.asList(kthConfidences));
exampleSet.getExampleTable().addAttributes(Arrays.asList(kthPredictions));
// now setting values
for (Example example : exampleSet) {
ArrayList<Tupel<Double, Integer>> labelConfidences = new ArrayList<Tupel<Double, Integer>>(numberOfLabels);
for (i = 0; i < numberOfLabels; i++) {
labelConfidences.add(new Tupel<Double, Integer>(example.getValue(confidences[i]), i));
}
Collections.sort(labelConfidences);
for (i = 0; i < k; i++) {
Tupel<Double, Integer> tupel = labelConfidences.get(numberOfLabels - i - 1);
example.setValue(kthPredictions[i], tupel.getSecond()); // Can use index since
// mapping has been cloned
// from above
example.setValue(kthConfidences[i], tupel.getFirst());
}
}
// deleting old prediction / confidences
attributes.remove(predictedLabel);
if (getParameterAsBoolean(PARAMETER_REMOVE_OLD_PREDICTIONS)) {
for (i = 0; i < confidences.length; i++) {
attributes.remove(confidences[i]);
}
}
return exampleSet;
}
示例15: remap
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
/**
* Remaps the attributes in the exampleSet or writes into the exampleSet if a remapping is not
* possible.
*/
private void remap(ExampleSet exampleSet) throws ProcessStoppedException {
Attributes attributes = exampleSet.getAttributes();
OperatorProgress progress = null;
if (getShowProgress() && getOperator() != null && getOperator().getProgress() != null) {
progress = getOperator().getProgress();
progress.setTotal(affectedAttributeNames.length);
}
int progressCounter = 0;
for (String attributeName : affectedAttributeNames) {
Attribute attr = attributes.get(attributeName);
if (attr.isNominal()) {
NominalMapping mapping = attr.getMapping();
List<String> mappingValues = mapping.getValues();
for (String string : mappingValues) {
String replacement = replace(string);
int oldRepr = mapping.getIndex(string);
// Nothing to replace
if (replacement.equals(string)) {
continue;
}
// Replacement already present in mapping -> Replace in example set
else if (mappingValues.contains(replacement)) {
for (Example example : exampleSet) {
double oldValue = example.getValue(attr);
if (Tools.isEqual(oldRepr, oldValue)) {
int newRepr = mapping.getIndex(replacement);
example.setValue(attr, newRepr);
}
}
}
// Replacement not present in mapping -> Replace in mapping
else {
mapping.setMapping(replacement, oldRepr);
}
}
}
if (progress != null && ++progressCounter % OPERATOR_PROGRESS_STEPS == 0) {
progress.setCompleted(progressCounter);
}
}
}