WEKA: how to get the score from classifyInstance?

后端 未结 4 544
悲哀的现实
悲哀的现实 2020-12-19 17:11

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

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 17:25

    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.

提交回复
热议问题