error with NaiveBayes classifier when classify one instance with pretrained model
I have a trained dataset with 125 records. I'm going to classify new instance using NaiveBayesUpdatable. but when I run naiveBayes (under windows, using weka 3.4), I get the following error :
java.lang.ArrayIndexOutOfBoundsException: 126
at weka.estimators.DiscreteEstimator.getProbability(Unknown Source)
at weka.classifiers.bayes.NaiveBayes.distributionForInstance(Unknown Source)
at weka.classifiers.Classifier.classifyInstance(Unknown Source)
at Classifier.Naiv开发者_如何学GoeBayes.classifyInstance(NaiveBayes.java:190)
at Classifier.NaiveBayes.classifyWebPage(NaiveBayes.java:106)
when I run the J48 classifier, it runs with no problems.
thanks for any help\ideas.
I think i found the solution. i added the record to dataset and build classifier again. then I could classify it with no problem. but I don't know why j48 doesn't need to have record in it's dataset.
Are you calling updateClassifier() after classifyInstance()? NaiveBayes will only be updated if you do so. J48 is not an updateable classifier, so naturally, it must be rebuilt every time you add an instance. Performance-wise, it doesn't make such a big difference because J48 is an extremely fast learning algorithm.
In any case, I would advise looking at other classes that implement UpdateableClassifier (use F4 in Eclipse to get inheritance hierarchy), and comparing your results to them. NaiveBayes is good for very specific tasks, while IBk (Nearest Neighbor) is robust across many domains.
精彩评论