如何在WEKA API中查看所有分类的实例

时间:2013-04-16 20:02:42

标签: java classification weka prediction

我想查看我的分类实例。

我试过这样的事情:

for(int i = 0; i < dataSet.size(); i++) {
    double pred = nowy.classifyInstance(dataSet.instance(i));
    double actual = dataSet.instance(i).classValue();
    double[] dist = nowy.distributionForInstance(dataSet.instance(i));

    if (pred != actual)
    {
        System.out.print((i+1));
        System.out.print(" - ");
        System.out.print(dataSet.instance(i).toString(dataSet.classIndex()));
        System.out.print(" - ");
        System.out.print(dataSet.classAttribute().value((int) pred));
        System.out.print(" - ");

        if (pred != dataSet.instance(i).classValue())
            System.out.print("no");
        else
            System.out.print("yes");
        System.out.println();

    }

}

但似乎它不能很好地工作,因为正确/错误分类的实例的数量与统计输出不同。

1 个答案:

答案 0 :(得分:0)

您还可以使用WEKA API中提供的Evaluation类一次性测试所有实例。

Instances trainData = ds.getDataset(); //get training dataset

SMO sm = new SMO(); //build classifier

sm.buildClassifier(data); //train classifier

Instances testData = ds.getDataSet(); //now get the test set

Evaluation eval = new Evaluation(data); //for recording results

eval.evaluateModel(sm, testData);

System.out.println(eval.toMatrixString()); //gives the confusion matrix for predictions