没有得到未标记的类的结果

时间:2015-02-20 12:03:32

标签: java netbeans weka

    Instances new_testing_data = Filter.useFilter(testing_data, remove2);
    new_testing_data.setClassIndex(new_testing_data.numAttributes()-1);

    double pred;
    String actual, prediction, adm_no;

    for (int i = 0; i < new_testing_data.numInstances(); i++) {
        System.out.println("Classifying Instances " + i);
        pred = j48.classifyInstance(new_testing_data.instance(i));
....
....

我有一套带有标记类的训练集和带有未标记类的测试集, 我需要在测试集上得到预测结果。我是从上面的代码做的吗?任何指导都会非常感激,这个项目一直扼杀我的所有日​​夜。

1 个答案:

答案 0 :(得分:0)

试试这个:

try {
            fc.buildClassifier(data);
        } catch (Exception e) {
            System.out.println("Cannot build classifier");
        }
        //<---building of the classifier ends
        //Classification--->
        clsLabel = new double[testData.numInstances()]; //holds class label of the test documents
        //for each test document--->
        for (int i = 0; i < testData.numInstances(); i ++){
            try {
                clsLabel[i] = fc.classifyInstance(testData.instance(i));
            } catch (Exception e) {
                System.out.println("Error from Classification.classify(). Cannot classify instance");
            }
            testData.instance(i).setClassValue(clsLabel[i]);
        }//end for
        //<---classification ends