import com.rapidminer.tools.Ontology;
Integer numberOfAttributes = operator.getProcess().macroHandler.getMacro("numberOfAttributes").toInteger();
Integer numberOfExamples = operator.getProcess().macroHandler.getMacro("numberOfExamples").toInteger();
Attribute[] attributes = new Attribute[numberOfAttributes];
for (i = 0; i < numberOfAttributes; i++) {
name = "att_" + i.toString();
attributes[i] = AttributeFactory.createAttribute(name, Ontology.STRING);
}
MemoryExampleTable table = new MemoryExampleTable(attributes);
DataRowFactory ROW_FACTORY = new DataRowFactory(0);
String[] values = new String[numberOfAttributes];
for (j = 0; j < numberOfExamples; j++){
for (i = 0; i < numberOfAttributes; i++) {
values[i] = 0;
}
DataRow row = ROW_FACTORY.create(values, attributes);
table.addDataRow(row);
}
ExampleSet exampleSet = table.createExampleSet();
return exampleSet;
- numberOfAttributes
- numberOfExamples
These are set in the process context but can easily be defined in other ways.
The attribute names are prefixed with "att_" and the default value is 0. A bit of coding can change this.
Of course, the operators that are already available can be used to recreate this but my personal best is 8 operators to recreate the Groovy script above. I figured a 7 click saving was worth investing a bit of time to get.
Edit: I improved my personal best to 4 operators.
Edit: I improved my personal best to 4 operators.
Thanks for sharing this Andrew.. very useful for what I want to do, and I'm going to try it.
ReplyDeleteMay I ask what do you mean by "operators that are already available can be used to recreate this"? Is there a way to create a dynamic ExampleSet using ready operators?
Hello JMPF
DeleteIt is possible to do the same thing as the Groovy script using standard operators. I've done it using 4 operators although I can't remember where I saved it.
regards
Andrew