Traverse trough dataset in reverse order
wessel
New Altair Community Member
Dear All, I posted the script below a long time ago, it creates some attributes with values depending on previous data rows.
Is it possible to do the loop: for (Example e : exampleSet) { } in reverse order somehow?
import com.rapidminer.operator.Operator;
import com.rapidminer.Process;
import com.rapidminer.MacroHandler;
import com.rapidminer.tools.Ontology
ExampleSet exampleSet = operator.getInput(ExampleSet.class);
Attribute sum = AttributeFactory.createAttribute("sum", Ontology.REAL);
exampleSet.getExampleTable().addAttribute(sum);
exampleSet.getAttributes().addRegular(sum);
Attribute avg = AttributeFactory
.createAttribute("avg", Ontology.REAL);
exampleSet.getExampleTable().addAttribute(avg);
exampleSet.getAttributes().addRegular(avg);
last = 0;
n = 0;
for (Example e : exampleSet) {
e["sum"] = e["abs"] + last; // iterate over an attribute using the name of the attribute
last = e["sum"];
n++;
e["avg"] = last / n;
}
return exampleSet
Is it possible to do the loop: for (Example e : exampleSet) { } in reverse order somehow?
import com.rapidminer.operator.Operator;
import com.rapidminer.Process;
import com.rapidminer.MacroHandler;
import com.rapidminer.tools.Ontology
ExampleSet exampleSet = operator.getInput(ExampleSet.class);
Attribute sum = AttributeFactory.createAttribute("sum", Ontology.REAL);
exampleSet.getExampleTable().addAttribute(sum);
exampleSet.getAttributes().addRegular(sum);
Attribute avg = AttributeFactory
.createAttribute("avg", Ontology.REAL);
exampleSet.getExampleTable().addAttribute(avg);
exampleSet.getAttributes().addRegular(avg);
last = 0;
n = 0;
for (Example e : exampleSet) {
e["sum"] = e["abs"] + last; // iterate over an attribute using the name of the attribute
last = e["sum"];
n++;
e["avg"] = last / n;
}
return exampleSet
Tagged:
0