本文整理汇总了Java中com.rapidminer.example.table.NominalMapping.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java NominalMapping.getIndex方法的具体用法?Java NominalMapping.getIndex怎么用?Java NominalMapping.getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapidminer.example.table.NominalMapping
的用法示例。
在下文中一共展示了NominalMapping.getIndex方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例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: 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);
}
示例4: 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);
}
}
}
示例5: 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);
}
}
}
}
}
示例6: 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++;
}
}
}
示例7: 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);
}
示例8: 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);
}
}
}
示例9: 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);
}
}
}
}
示例10: 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++;
}
}
}
示例11: doWork
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
// sanity checks
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// checking preconditions
Attribute label = exampleSet.getAttributes().getLabel();
if (label == null) {
throw new UserError(this, 105);
}
if (!label.isNominal()) {
throw new UserError(this, 101, label, "threshold finding");
}
exampleSet.recalculateAttributeStatistics(label);
NominalMapping mapping = label.getMapping();
if (mapping.size() != 2) {
throw new UserError(this, 118, new Object[] { 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()));
}
示例12: doWork
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的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()));
}
示例13: 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);
}
}
}
示例14: doWork
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
// sanity checks
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// checking preconditions
Attribute label = exampleSet.getAttributes().getLabel();
exampleSet.recalculateAttributeStatistics(label);
if (label == null)
throw new UserError(this, 105);
if (!label.isNominal())
throw new UserError(this, 101, label, "threshold finding");
NominalMapping mapping = label.getMapping();
if (mapping.size() != 2)
throw new UserError(this, 118, new Object[] { 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;
}
}
// 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()));
}