本文整理汇总了Java中com.rapidminer.example.table.NominalMapping.size方法的典型用法代码示例。如果您正苦于以下问题:Java NominalMapping.size方法的具体用法?Java NominalMapping.size怎么用?Java NominalMapping.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapidminer.example.table.NominalMapping
的用法示例。
在下文中一共展示了NominalMapping.size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例2: 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);
}
示例3: 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));
}
示例4: 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;
}
示例5: 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;
}
示例6: 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()));
}
示例7: apply
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
Attribute attribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
// some checks
if (attribute == null) {
throw new AttributeNotFoundError(this, PARAMETER_ATTRIBUTE_NAME, getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
}
if (!attribute.isNominal()) {
throw new UserError(this, 119, new Object[] { attribute.getName(), this.getName() });
}
String newValue = getParameterAsString(PARAMETER_NEW_VALUE);
if (attribute instanceof BinominalAttribute) {
Attribute newAttribute = AttributeFactory.createAttribute(Ontology.NOMINAL);
ExampleTable table = exampleSet.getExampleTable();
table.addAttribute(newAttribute);
NominalMapping originalMapping = attribute.getMapping();
NominalMapping newMapping = newAttribute.getMapping();
for (int i = 0; i < originalMapping.size(); i++) {
newMapping.mapString(originalMapping.mapIndex(i));
}
newAttribute.getMapping().mapString(newValue);
for (Example example : exampleSet) {
example.setValue(newAttribute, example.getValue(attribute));
}
exampleSet.getAttributes().addRegular(newAttribute);
AttributeRole role = exampleSet.getAttributes().getRole(attribute);
exampleSet.getAttributes().remove(attribute);
newAttribute.setName(attribute.getName());
if (role.isSpecial()) {
exampleSet.getAttributes().setSpecialAttribute(newAttribute, role.getSpecialName());
}
} else {
attribute.getMapping().mapString(newValue);
}
return exampleSet;
}
示例8: 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()));
}
示例9: 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;
}
示例10: 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()));
}
示例11: apply
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
Attribute attribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
// some checks
if (attribute == null) {
throw new UserError(this, 111, getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
}
if (!attribute.isNominal()) {
throw new UserError(this, 119, new Object[] { attribute.getName(), this.getName() });
}
String newValue = getParameterAsString(PARAMETER_NEW_VALUE);
if (attribute instanceof BinominalAttribute) {
Attribute newAttribute = AttributeFactory.createAttribute(Ontology.NOMINAL);
ExampleTable table = exampleSet.getExampleTable();
table.addAttribute(newAttribute);
NominalMapping originalMapping = attribute.getMapping();
NominalMapping newMapping = newAttribute.getMapping();
for (int i = 0; i < originalMapping.size(); i++) {
newMapping.mapString(originalMapping.mapIndex(i));
}
newAttribute.getMapping().mapString(newValue);
for (Example example: exampleSet) {
example.setValue(newAttribute, example.getValue(attribute));
}
exampleSet.getAttributes().addRegular(newAttribute);
AttributeRole role = exampleSet.getAttributes().getRole(attribute);
exampleSet.getAttributes().remove(attribute);
newAttribute.setName(attribute.getName());
if (role.isSpecial()) {
exampleSet.getAttributes().setSpecialAttribute(newAttribute, role.getSpecialName());
}
} else {
attribute.getMapping().mapString(newValue);
}
return exampleSet;
}