Antoine
Antoine

Reputation: 11

Imposible to use PCA filter from Weka in java code

I have to implement a classifier in java on a dataset with a large number of attributes (1000).

My problem is when I want to use a pca filter on my dataset. I did it with the "Explorer" Preprocess interface of Weka and it works (I get 20 attributes).

It is impossible for me to create the filter, the console return me an error that I don't understand.

Here a simple class using the filter:

import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.classifiers.bayes.NaiveBayes;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.PrincipalComponents;

public class ClassifierWithFilter{
        public static void main(String args[]) throws Exception{
        //load dataset
        DataSource source = new DataSource("path/trainingfile.arff");
        Instances trainingSet = source.getDataSet();
        //set class index to the last attribute
        trainingSet.setClassIndex(trainingSet.numAttributes()-1);

        //filter
        PrincipalComponents pca = new PrincipalComponents();
        Instances newTrainingSet= Filter.useFilter(dataSet, pca);
        System.out.println(newTrainingSet);

        //the base classifier
        NaiveBayes nb = new NaiveBayes();
        nb.buildClassifier(trainingSet);
        System.out.println(nb);
    }
}

The error:

Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix
   at weka.api.ClassifierWithFilter.main(ClassifierWithFilter.java:38)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Matrix
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

If I put the 3 lines below //filter, the error disappears.

I am using the jar package of weka-3-8-1.

Upvotes: 0

Views: 397

Answers (1)

Antoine
Antoine

Reputation: 11

I finally found the error, I just use a previous version of the Weka package: Weka 3.6.0 and the error disappear.

Upvotes: 1

Related Questions