1

私はWEKA、次のコードに出くわしました:

Instances train = DataSource.read(args[0]);
train.setClassIndex(train.numAttributes() - 1);
Instances test = DataSource.read(args[1]);
test.setClassIndex(test.numAttributes() - 1);
// train classifier
J48 cls = new J48();
cls.buildClassifier(train);
// output predictions
System.out.println("# - actual - predicted - distribution");
for (int i = 0; i < test.numInstances(); i++) {
    double pred = cls.classifyInstance(test.instance(i));
    double[] dist = cls.distributionForInstance(test.instance(i));
    System.out.print((i+1) + " - ");
    System.out.print(test.instance(i).toString(test.classIndex()) + " - ");
    System.out.print(test.classAttribute().value((int) pred) + " - ");
    System.out.println(Utils.arrayToString(dist));
}

ここでの目的は、データのテスト セットに対して事前に作成された分類器を実行し、実際のクラス、予測されたクラス、およびクラス メンバーシップ値の分布を出力することです。1行を除いてすべてを理解しています:

System.out.print(test.classAttribute().value((int) pred) + " - ");

「テスト」がインスタンスのグループである場合、上記のステートメントは、for ループ内の現在のインスタンスの予測されたクラス値をどのように出力できるでしょうか?

ありがとうアビシェクS

4

1 に答える 1

1

I think that test.classAttribute() gives you all the classes that the test instances could be assigned to. The second part .value((int) pred) then selects the class out of this group which matches to pred, which is the predicted class for the current test instance.

于 2012-06-04T09:59:31.597 に答える