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
"Problem using PCA"
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);
attributes.add(label);
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) {
e.printStackTrace();
}
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
Igor
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);
attributes.add(label);
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) {
e.printStackTrace();
}
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
Igor
0
Answers
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: And before you ask: Yes the tutorial needs some update...
Greetings,
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,
Igor
the tutorial will be outdated completely as soon as RapidMiner 5 is released. We will see, how detailed the new chapter will be
Greetings,
Sebastian