WEKA: how to get the score from classifyInstance?

南楼画角 提交于 2019-11-28 04:37:58

问题


I'm using a FilteredClassifier.classifyInstance() to classify my instances in weka.

I have 2 classes (true and false) and I have many positives, so I actually need to know the score of each isntance to get the best positive.

You know how I could get the score from my weka classifier ?

thanks

Update: I've also tried to use distributionForInstance, but for each instance I always get an array with [1.0, 0.0].

I actually need to compare several instances to see which one is the most reliable, which one has more changes to have been classified correctly.


回答1:


distributionForInstance(Instance anInstance) is the method you need. It gives you a Double array showing the confidence for each of your classes. I am using Weka 3.6. and it works well for me. If you always get the same values, your classifier is not trained well and not discriminative at all. In that case, you should always get the same class predicted. Did you balance your training set?




回答2:


After you have run the classifier on your data, you can visualize the data by right clicking on the test in the " Result list " There are lots of other funcitons on this right click menu that will allow you to gain scores from weka classifiers.




回答3:


distributionForInstance(Instance anInstance) seems right.

Maybe it is not working for you because the classifier doesn't know you'd need the confidence values? For example for LibSVM on Weka Java, you need to set setProbabilityEstimates to true, in order to use the scores.




回答4:


Suppose that your model is already trained.

Then, you can make predictions with distributionForInstance. This command produces an array consisting of two items (because there are two classes on your dataset: true and false)

double[] distributions = model.distributionForInstance(new_instance);

After then, index of the greatest item in distributions array would be classification result.

Assume that distributions = {0.9638458988630731, 0.03615410113692686}. In this case, your new instance would be classified as class_0 because 1st item is greater than 2nd item in distributions array.

You can also get this index with classifyInstance command.

double classifiedIndex = model.classifyInstance(new_instance);

classifiedIndex value would be 0 for distributions = {0.9638458988630731, 0.03615410113692686}.

Finally, you can get the class name as true or false instead of class index.

new_instance.setClassValue(classifiedIndex); //firstly, assigned classified index to new_instance.
String classifiedText = new_instance.stringValue(new_instance.numAttributes());

This code block produces false.

You might examine this GitHub project for both regression and classification.



来源:https://stackoverflow.com/questions/5563339/weka-how-to-get-the-score-from-classifyinstance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!