Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weka - how to print incorrectly classified instances

my weka output shows:

Correctly Classified Instances       32083               94.0244 %
Incorrectly Classified Instances      2039                5.9756 %

I want to be able to print out what the incorrect instances were so i can make adjustments and understand why they were misclassified.

my print method is below.
i am attempting to find instances whose predicted class value were not equal to the actual class value and then print its attributes.
but when i do this the attribute enumeration is not printing anything.

Does anyone have a suggestion for how to print out the misclassified instances?

thanks much.

private void printSummary(Classifier base, Evaluation eval, Instances data) throws Exception
{
    // output evaluation
    System.out.println();
    System.out.println("=== Setup ===");
    System.out.println("Classifier: " + classifierName.getClass().getName() + " " + Utils.joinOptions(base.getOptions()));
    System.out.println("Dataset: " + data.relationName());
    System.out.println();

    // output predictions
    System.out.println("# - actual - predicted - error - distribution - token");
    for (int i = 0; i < data.numInstances(); i++) 
    {
        double pred = base.classifyInstance(data.instance(i));
        double actual = data.instance(i).classValue();
        double[] dist = base.distributionForInstance(data.instance(i));

        if (pred != actual)
        {
            System.out.print((i+1));
            System.out.print(" - ");
            System.out.print(data.instance(i).toString(data.classIndex()));
            System.out.print(" - ");
            System.out.print(data.classAttribute().value((int) pred));
            System.out.print(" - ");
            if (pred != data.instance(i).classValue())
                System.out.print("yes");
            else
                System.out.print("no");
            System.out.print(" - ");
            System.out.print(Utils.arrayToString(dist));
            System.out.print(" - ");
            data.instance(i).enumerateAttributes().toString();
            System.out.println();
        }
    }

    System.out.println(eval.toSummaryString());
    System.out.println(eval.toClassDetailsString());
    System.out.println(eval.toMatrixString());
}
like image 842
britt Avatar asked Nov 05 '22 12:11

britt


1 Answers

I do this that way:

  1. Train classifier.
  2. For each instance I call 'classifier.explain'
  3. If classification is incorrect I store them by incorrect probability (from worst error to least confident error)
  4. Most confident error give me ideas what features should be added to classifier.
like image 144
yura Avatar answered Nov 10 '22 15:11

yura