RapidMiner 9.7 is Now Available

Lots of amazing new improvements including true version control! Learn more about what's new here.


"Problem using PCA"

IgorIgor Member Posts: 6 Contributor II
edited May 2019 in Help
Hi RapidMiner team,

I become ArrayIndexOutOfBoundsException when I try to apply PCA to my data. I created also some other simplified code (listed below) - the error remains. I reused the code from RapidMiner PDF manual so I hope it must be more or less okay.. Here is it:

// Create 10 attributes
List<Attribute> attributes = new LinkedList<Attribute>();
for(int a=0;a<10;a++) { attributes.add(AttributeFactory.createAttribute("a" + a,Ontology.REAL)); }
Attribute label = AttributeFactory.createAttribute("class",Ontology.NOMINAL);
Random rand = new Random();
MemoryExampleTable table = new MemoryExampleTable(attributes);

// Create 8 data intances and fill the data
for(int d = 0; d < 8; d++) {
  double[] data = new double[attributes.size()];
  for(int dim=0;dim<10;dim++) { data[dim] = rand.nextDouble(); }
  if(rand.nextBoolean()) { data[attributes.size()-1] = 1d; }
  else { data[attributes.size()-1] = 0d; }
  table.addDataRow(new DoubleArrayDataRow(data));
ExampleSet exampleSet = table.createExampleSet(label);

// Make PCA
try {
  Operator pca = OperatorService.createOperator(PrincipalComponentsTransformation.class);
  IOContainer container = new IOContainer(new IOObject[] {exampleSet});
  container = pca.apply(container);
} catch(Exception e) {

The exception trace is:
com.rapidminer.operator.UserError: PrincipalComponents caused an error: java.lang.ArrayIndexOutOfBoundsException: 0
at com.rapidminer.operator.features.transformation.PrincipalComponentsTransformation.apply(PrincipalComponentsTransformation.java:69)
at com.rapidminer.operator.AbstractExampleSetProcessing.apply(AbstractExampleSetProcessing.java:48)
at com.rapidminer.operator.Operator.apply(Operator.java:671)
at ...
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at weka.filters.unsupervised.attribute.ReplaceMissingValues.batchFinished(Unknown Source)
at weka.filters.Filter.useFilter(Unknown Source)
at weka.attributeSelection.PrincipalComponents.buildAttributeConstructor(Unknown Source)
at weka.attributeSelection.PrincipalComponents.buildEvaluator(Unknown Source)
at com.rapidminer.operator.features.transformation.PrincipalComponentsTransformation.apply(PrincipalComponentsTransformation.java:67)

Maybe you have any idea?

Thanks in advance and kind regards


  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531   Unicorn
    Hi Igor,
    I have to mention two possible sources of error: On the one hand, I would prefer the PCA operator instead of the PrincipalComponentTransformation. Here has been some code duplication which is removed in Vega. Additionally the PCA operator provides a model, so that you can apply the same transformation later on, during application time on unknown data.
    The other more serious error is, that you created a nominal attribute, but did not create a mapping between numerical values and the represented nominal values. I guess, the following code would solve this problem:

    Attribute label = AttributeFactory.createAttribute("class",Ontology.NOMINAL);
    NominalMapping mapping = label.getMapping();
    if(rand.nextBoolean()) {
    data[attributes.size()-1] = mapping.mapString("positive");
    } else {
    data[attributes.size()-1] = mapping.mapString("negative");
    And before you ask: Yes the tutorial needs some update...

  • IgorIgor Member Posts: 6 Contributor II
    Hi Sebastian,

    thanks, it works! It could be really very nice if Chapter 7 from tutorial ("Integrating RapidMiner into your application") will grow a bit sometime ;-)

    Best regards,
  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531   Unicorn
    Hi Igor,
    the tutorial will be outdated completely as soon as RapidMiner 5 is released. We will see, how detailed the new chapter will be :)

Sign In or Register to comment.