How to Create Example Sets Using Groovy Script

MartinLiebigMartinLiebig Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,524 RM Data Scientist
edited December 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>();
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")
PoissonDistribution pos2 = new PoissonDistribution(40)
for(int i = 0; i < 10000; ++i){
row[0] = pos2.sample();
row[1] = attributes.get(1).getMapping().mapString("Class2")
// This line returns the first input as the first output
return examplesetBuilder.build();
- Sr. Director Data Solutions, Altair RapidMiner -
Dortmund, Germany
Sign In or Register to comment.