I have my model on my hard drive at d:\MultiNomial.model. That model can be run correctly from weka. The model was built to classify a text using StringToVector as a filter. I am using java to load that model using Weka API. This is my source code
import weka.core.*;
import weka.classifiers.bayes.NaiveBayesMultinomial;
import weka.core.converters.ConverterUtils.DataSource;
public class Classifier {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
NaiveBayesMultinomial NBM =(NaiveBayesMultinomial) weka.core.SerializationHelper.read("D:/MultiNomial.model");
DataSource source= new DataSource( "D:/test.arff");
Instances Testset=source.getDataSet() ;
Testset.setClassIndex(Testset.numAttributes()-1);
Instance newInstance=Testset.instance(0);
double PredictVal=NBM.classifyInstance(newInstance);
System.out.println(PredictVal);
}
}
but I had the following error when I tried to run it from Eclipse:
Exception in thread "main" java.lang.ClassCastException: weka.classifiers.meta.FilteredClassifier cannot be cast to weka.classifiers.bayes.NaiveBayesMultinomial
what is the issue?
In Weka I used FilteredClassifier -> Unsupervised-> Attribute->StringToVector. Then I chose NaiveBayesMultinomial and I saved my model in my drive. Now When I used Java, I got the error : weka.classifiers.meta.FilteredClassifier cannot be cast to weka.classifiers.bayes.NaiveBayesMultinomial.
I think there must be a way to tell the code how to reverse StringToVector then use :
NaiveBayesMultinomial NBM =(NaiveBayesMultinomial) weka.core.SerializationHelper.read("D:/MultiNomial.model")