I have a simple naive bayes classifier from WEKA. I’m using a directory structure and reading it in via the TextDirectoryLoader. The Directory structure is
Training_Data
Spam (folder)
text files
Ham (folder)
text files
I can get the distributions like this
for(Instance i: testInstances){
double [] distributions = classifier.distributionForInstance(i);
for(double d : distributions)
System.out.println(d);
}
what I want to do is get the category name to go along side the distribution so I can print it out like so
System.out.println("Category: "+/*something to get the category name*/+ ":"+ d);
I’ve been looking around for hours now and can’t figure out how to do it. Anyone know how?
You can use
instance.classAttribute().value(valIndex)wherevalIndexis the index of the category: