0
votes

I'm working on a Web Service writen in Java to use Weka algorith j48 to classify some atributes. First it builds the classifier and then it classifies an instance using the classifier tree.

This is part of the code i have for the classifydata method

fc.buildClassifier(train);
for (int i = 0; i < test.numInstances(); i++)
{
double pred = fc.classifyInstance(test.instance(i));
predicated = (test.classAttribute().value((int) pred));
}

being fc the FilteredClassifier that was previously set, being train the data used to build the classifier and test the instance to classify I'm also not sure if with this code i'm doing a good classification, if you could confirm that it would be nice.

What i really want is to get the "accuracy percentage". I don't really know if it is called like this but i don't know how else to reffer to it. Basicly i want something that will return the accuracy percentage of the classify result. Imagine i have simple a tree that has only 2 classifications, "1" or "2". Imagine i classify an instance and the result is "2". Now i want something that will return how accurate it is for the instance to be a "2", and who says accuracy says probability of being really a "2"

I hope i made myself clear because this is kinda new to me aswell

1

1 Answers

1
votes

For this you have to use the distributionForInstance() method:

double[] probabilityDistribution = fc.distributionForInstance(test.instance[i])

Then if you have the two class values "1" and "2" (and you added the attribute/class values in that order to your class attribute), you can get the probabilities with which the given test instance is of one of the two class values by:

// Probability of the test instance beeing a "1"
double classAtt1Prob = probabilityDistribution[0];
// Probability of the test instance beeing a "2"
double classAtt2Prob = probabilityDistribution[1];