The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

How to Create Example Sets Using Groovy Script

MartinLiebigMartinLiebig Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,533 RM Data Scientist
edited November 2018 in Knowledge Base

 Sometimes you want to create custom data sets which are beyond the options of the Generate Data operator.

 

One way to do this is to use the Execute Script operator which leverages groovy script. Here is a groovy script to start off with. It generates an example set with two attributes. One is numerical and has different Poissoin distributed values in. The other is nominal and has two different class values in.

 

import com.rapidminer.example.utils.ExampleSetBuilder;
import com.rapidminer.example.utils.ExampleSets;
import com.rapidminer.tools.Ontology;
import org.apache.commons.math3.distribution.PoissonDistribution;

List<Attribute> attributes = new ArrayList<Attribute>();
attributes.add(AttributeFactory.createAttribute("data",Ontology.REAL));
attributes.add(AttributeFactory.createAttribute("class",Ontology.STRING));
ExampleSetBuilder examplesetBuilder = ExampleSets.from(attributes);
PoissonDistribution pos = new PoissonDistribution(20)
double[] row = new double[2];
for(int i = 0; i < 10000; ++i){
row[0] = pos.sample();
row[1] = attributes.get(1).getMapping().mapString("Class1")
examplesetBuilder.addRow(row)
}
PoissonDistribution pos2 = new PoissonDistribution(40)
for(int i = 0; i < 10000; ++i){
row[0] = pos2.sample();
row[1] = attributes.get(1).getMapping().mapString("Class2")
examplesetBuilder.addRow(row)
}
// This line returns the first input as the first output
return examplesetBuilder.build();
- Sr. Director Data Solutions, Altair RapidMiner -
Dortmund, Germany
Tagged:
Sign In or Register to comment.