【问题标题】:weka decision tree javaweka决策树java
【发布时间】:2014-11-23 14:54:06
【问题描述】:

我想列出所有预测。

我有这个代码:

//Get File
        BufferedReader reader = new BufferedReader(new FileReader(PATH + "TempArffFile.arff"));

        //Get the data
        Instances data = new Instances(reader);
        reader.close();

        //Setting class attribute 
        data.setClassIndex(data.numAttributes() - 1);

        //Make tree
        J48 tree = new J48();
        String[] options = new String[1];
        options[0] = "-U"; 
        tree.setOptions(options);
        tree.buildClassifier(data);

        //Print tree
        System.out.println(tree);

它工作正常,我可以看到打印的树,但不知道如何从这里使用它。 我想为每个根创建一个列表,我该怎么做?

【问题讨论】:

    标签: java weka decision-tree


    【解决方案1】:

    如果您想要所有测试预测的列表,您可以使用以下代码(提供的示例代码here):

     import weka.core.Instances;
     import weka.classifiers.Evaluation;
     import weka.classifiers.trees.J48;
     ...
     Instances train = ...   // from somewhere
     Instances test = ...    // from somewhere
     // train classifier
     Classifier cls = new J48();
     cls.buildClassifier(train);
     // evaluate classifier and print some statistics
     Evaluation eval = new Evaluation(train);
     eval.evaluateModel(cls, test);
     System.out.println(eval.toSummaryString("\nResults\n======\n", false));
    

    如果您愿意,也可以使用J48.classifyInstance() 来预测单个实例。

    【讨论】:

    • 那不是我想要的。我有这个结果:title 1 |位置匹配 好 | | countryCode > 1-> 不好 |位置匹配> 1-> 好。现在我有一些物品,想检查它是否好。标题 =2 ,位置 =0 ,国家代码 = 0 => 所以很好。我怎样才能在java中进行检查?
    • 您的意思是您想获取树中的所有规则吗?抱歉,这个问题似乎是在询问预测。
    • 我的错误我会问一个新的。您的代码确实适用于预测
    猜你喜欢
    • 2015-02-06
    • 2014-11-25
    • 2021-05-16
    • 2020-08-25
    • 2014-12-29
    • 2017-01-25
    • 2018-09-27
    • 2021-12-10
    • 2016-09-02
    相关资源
    最近更新 更多