I am trying to use the filtered classifier on data of the following format:
real,real,real,...,nominal
where I have 138 real values and a single nominal string representing the class. I am using J48 as the base classifier and the supervised discretization filter as follows:
Filter discretize = new weka.filters.supervised.attribute.Discretize();
FilteredClassifier fc = new FilteredClassifier();
discretize.setInputFormat(m_data);
J48 ft = new J48();
ft.setOptions(wekaOptions);
fc.setFilter(discretize);
fc.setClassifier(ft);
fc.buildClassifier(m_data);
Where m_data
is my (labelled) training data with m_data.setClassIndex(m_data.numAttributes()-1)
set. No problems (that I can see) here.
I serialize this model and load it later. I then use it to classify unseen/new data like so:
Instance unlabeledInstance = new DenseInstance(1.0,features);
unlabeledInstance.setDataset(m_instances);
m_classifier.classifyInstance(unlabeledInstance);
where features is a double[]
that follows the format of the input data, but with no nominal class value. Here m_instances
is just loaded from the training data file with
m_instances.setClassIndex(m_instances.numAttributes()-1)
set.
However, when running m_classifier.classifyInstance(unlabeledInstance)
, I receive an arrayOutOfBoundsException
error. Can anyone shed any light on this?
The trace is:
07-13 15:15:35.383: W/System.err(30659): java.lang.ArrayIndexOutOfBoundsException: length=138; index=138
07-13 15:15:35.383: W/System.err(30659): at weka.core.DenseInstance.value(DenseInstance.java:309)
07-13 15:15:35.383: W/System.err(30659): at weka.filters.unsupervised.attribute.Discretize.convertInstance(Discretize.java:1047)
07-13 15:15:35.383: W/System.err(30659): at weka.filters.unsupervised.attribute.Discretize.input(Discretize.java:389)
07-13 15:15:35.383: W/System.err(30659): at weka.classifiers.meta.FilteredClassifier.distributionForInstance(FilteredClassifier.java:425)
07-13 15:15:35.383: W/System.err(30659): at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:72)
It looks like its expecting the class value to be set.