Reputation: 2862
When i am trying to evaluate a new testing data on already trained classifier it brings me null point exception.
Here is the code
String[] optionsj = new String[2];
optionsj[0] = "-C";
optionsj[1] = "0.25";
// a decision tree
//Training
Classifier cls = new J48();
cls.setOptions(optionsj);
Evaluation eval = new Evaluation(data);
Random rand = new Random(1); // using seed = 1
int folds = 10;
eval.crossValidateModel(cls, data, folds, rand);
System.out.println(eval.toSummaryString());
System.out.println(eval.toClassDetailsString());
//Testing
Evaluation evaltest = new Evaluation(data);
evaltest.evaluateModel(cls, data2); // line 193
System.out.println(evaltest.toSummaryString());
//data and data2 are two instances of same dataset.
Error i am getting is
Exception in thread "main" java.lang.NullPointerExceptionat
at weka.classifiers.trees.J48.distributionForInstance(Unknown Source)
at weka.classifiers.Evaluation.evaluateModelOnceAndRecordPrediction(Unknown Source)
at weka.classifiers.Evaluation.evaluateModel(Unknown Source)
at dentis.Simplified.main(Simplified.java:193)
I cant print the dataset out without a problem. What is this problem? why it occur and how to fix it?
Upvotes: 0
Views: 703
Reputation: 1947
when you are using evaluateModel you need to build the classifier on the training set first.
cls.buildClassifier(data);
Upvotes: 2