Before I decided to post the problem I’m having I’ve read a lot of posts and I still couldn’t get a clear answer. So here it is:
Using weka I have trained a NaiveBayesTree with my training data that looks like that:
(the values are simplified, and there's 20000 rows in the training set)
AF3,F7,F3,FC5,T7,T8,FC6,F4,F8,AF4,Action
-1,2,0,1,0,0,-1,-0,-0,-0,NEUTRAL
-2,1,0,2,-0,0,-0,0,-1,-0,RIGHT
-1,1,0,2,-0,0,-1,0,-1,-0,LEFT
Now I would like to use the saved model in my program to determine what is the class distribution in the given 128 rows of test data. For this 128 rows I do not have the classes (Action attribute) assigned. Basically I would like the model to answer that 🙂
So the test rows looks like this:
-1,1,0,2,-0,0,-1,0,-1,-0,?
So far I’ve came up with this code:
Classifier nbTree = (Classifier)SerializationHelper.read(Model) as NBTree;
Instances testInstances = TestSet();
testInstances.setClassIndex(10);
for (int i = 0; i < testInstances.numInstances(); i++)
{
Instance instance = testInstances.instance(i);
double assignedClass = nbTree.classifyInstance(instance);
double[] distributionForInstance = nbTree.distributionForInstance(instance);
}
But it will always generate 0 for each assignedClass and distributionForInstance will always have exactly one element with different values:
0,9412543332996
0,9412543332996
0,9412543332996
0,9412543332996
0,0577106296809467
0,315216251505317
0,9412543332996
0,9412543332996
0,315216251505317
0,315216251505317
0,863366140658458
0,9412543332996
0,9412543332996
0,9412543332996
0,9412543332996
0,783615619462732
I walking in circles fro two days now and would really appreciate some help 🙂
I did some more research and came across this article: http://weka.wikispaces.com/Making+predictions which helped me to write the following code:
This code allows me to check what class is being predicted on a given instance as well as the probability values of all of the classes that were taken under consideration.
I hope this will help someone 🙂