本文整理汇总了Java中com.rapidminer.example.table.NominalMapping.mapString方法的典型用法代码示例。如果您正苦于以下问题:Java NominalMapping.mapString方法的具体用法?Java NominalMapping.mapString怎么用?Java NominalMapping.mapString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapidminer.example.table.NominalMapping
的用法示例。
在下文中一共展示了NominalMapping.mapString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTargetAttributes
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public Attributes getTargetAttributes(ExampleSet parentSet) {
SimpleAttributes attributes = new SimpleAttributes();
// add special attributes to new attributes
Iterator<AttributeRole> specialRoles = parentSet.getAttributes().specialAttributes();
while (specialRoles.hasNext()) {
attributes.add(specialRoles.next());
}
// add regular attributes
for (Attribute attribute : parentSet.getAttributes()) {
if (!attribute.isNumerical() || !attributeNames.contains(attribute.getName())) {
attributes.addRegular(attribute);
} else {
// create nominal mapping
SortedSet<Tupel<Double, String>> ranges = rangesMap.get(attribute.getName());
if (ranges.size() > 1) {
NominalMapping mapping = new PolynominalMapping();
for (Tupel<Double, String> rangePair : ranges) {
mapping.mapString(rangePair.getSecond());
}
// giving new attributes old name: connection to rangesMap
attributes.addRegular(new ViewAttribute(this, attribute, attribute.getName(), Ontology.POLYNOMINAL,
mapping));
}
}
}
return attributes;
}
示例2: createBinominalValueAttribute
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
private Attribute createBinominalValueAttribute(Attribute attribute, String value) {
NominalMapping mapping = new BinominalMapping();
mapping.mapString("false");
mapping.mapString("true");
// giving new attributes old name_value
String newName = createAttributeName(attribute.getName(), value);
Attribute newAttribute = new ViewAttribute(this, attribute, newName, Ontology.BINOMINAL, mapping);
binominalAttributeValueMap.put(newAttribute, (double) attribute.getMapping().mapString(value));
return newAttribute;
}
示例3: getTargetAttributes
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public Attributes getTargetAttributes(ExampleSet parentSet) {
SimpleAttributes attributes = new SimpleAttributes();
// add special attributes to new attributes
Iterator<AttributeRole> specialRoles = parentSet.getAttributes().specialAttributes();
while (specialRoles.hasNext()) {
attributes.add(specialRoles.next());
}
// add regular attributes
for (Attribute attribute : parentSet.getAttributes()) {
if (!attribute.isNumerical() || !attributeNames.contains(attribute.getName())) {
attributes.addRegular(attribute);
} else {
// create nominal mapping
SortedSet<Tupel<Double, String>> ranges = rangesMap.get(attribute.getName());
if (ranges.size() > 1) {
NominalMapping mapping = new PolynominalMapping();
for (Tupel<Double, String> rangePair : ranges) {
mapping.mapString(rangePair.getSecond());
}
// giving new attributes old name: connection to rangesMap
attributes.addRegular(
new ViewAttribute(this, attribute, attribute.getName(), Ontology.POLYNOMINAL, mapping));
}
}
}
return attributes;
}
示例4: getTargetAttributes
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
public Attributes getTargetAttributes(ExampleSet parentSet) {
SimpleAttributes attributes = new SimpleAttributes();
// add special attributes to new attributes
Iterator<AttributeRole> specialRoles = parentSet.getAttributes().specialAttributes();
while (specialRoles.hasNext()) {
attributes.add(specialRoles.next());
}
// add regular attributes
for (Attribute attribute : parentSet.getAttributes()) {
if (!attribute.isNumerical() || !attributeNames.contains(attribute.getName())) {
attributes.addRegular(attribute);
} else {
// create nominal mapping
SortedSet<Tupel<Double, String>> ranges = rangesMap.get(attribute.getName());
if (ranges.size() > 1) {
NominalMapping mapping = new PolynominalMapping();
for (Tupel<Double, String> rangePair : ranges) {
mapping.mapString(rangePair.getSecond());
}
// giving new attributes old name: connection to rangesMap
attributes.addRegular(new ViewAttribute(this, attribute, attribute.getName(), Ontology.POLYNOMINAL, mapping));
}
}
}
return attributes;
}
示例5: 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;
}
示例6: createExampleSet
import com.rapidminer.example.table.NominalMapping; //导入方法依赖的package包/类
@Override
public ExampleSet createExampleSet() throws OperatorException {
// init
int numberOfExamples = getParameterAsInt(PARAMETER_NUMBER_EXAMPLES);
int numberOfAttributes = getParameterAsInt(PARAMETER_NUMBER_OF_ATTRIBUTES);
int numberOfValues = getParameterAsInt(PARAMETER_NUMBER_OF_VALUES);
if (numberOfValues < 2) {
logWarning("Less than 2 different values used, change to '2'.");
numberOfValues = 2;
}
getProgress().setTotal(numberOfAttributes + numberOfExamples);
// create mapping once, clone for each attribute
NominalMapping mapping = new PolynominalMapping();
int type = Ontology.NOMINAL;
for (int v = 0; v < numberOfValues; v++) {
mapping.mapString("value" + v);
}
// create table
List<Attribute> attributes = new LinkedList<Attribute>();
for (int m = 0; m < numberOfAttributes; m++) {
Attribute current = AttributeFactory.createAttribute("att" + (m + 1), type);
current.setMapping((NominalMapping) mapping.clone());
attributes.add(current);
getProgress().step();
}
Attribute label = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
label.getMapping().mapString("negative");
label.getMapping().mapString("positive");
attributes.add(label);
ExampleSetBuilder builder = ExampleSets.from(attributes).withExpectedSize(numberOfExamples);
// create data
RandomGenerator random = RandomGenerator.getRandomGenerator(this);
for (int n = 0; n < numberOfExamples; n++) {
double[] features = new double[numberOfAttributes];
for (int a = 0; a < features.length; a++) {
features[a] = random.nextIntInRange(0, numberOfValues);
}
double[] example = features;
if (label != null) {
example = new double[numberOfAttributes + 1];
System.arraycopy(features, 0, example, 0, features.length);
if (features.length >= 2) {
example[example.length - 1] = features[0] == 0 || features[1] == 0
? label.getMapping().mapString("positive") : label.getMapping().mapString("negative");
} else if (features.length == 1) {
example[example.length - 1] = features[0] == 0 ? label.getMapping().mapString("positive")
: label.getMapping().mapString("negative");
} else {
example[example.length - 1] = label.getMapping().mapString("positive");
}
}
builder.addRow(example);
getProgress().step();
}
getProgress().complete();
// create example set and return it
return builder.withRole(label, Attributes.LABEL_NAME).build();
}
示例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 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;
}