0

我想-C在 J48 中设置参数并运行三个存储在哈希表中的特征选择算法。我想比较准确性、真阳性、真阴性、F1 等三者的性能。但是当我运行所有特征选择算法时,它们返回给我相同的输出......我做错了什么吗?

    Hashtable<String, ASEvaluation> search=new Hashtable<String, ASEvaluation>();

    Instances training_data = new Instances(new BufferedReader(
            new FileReader("test.arff")));
    training_data.setClassIndex(training_data.numAttributes() - 1);
    topAttributes = new int[training_data.numAttributes()];

    AttributeSelectedClassifier classifier = new AttributeSelectedClassifier();
 AttributeSelection attsel = new AttributeSelection();

    search.put("Infogain", new InfoGainAttributeEval());
    search.put("SymmetricalUncertAttribute",new SymmetricalUncertAttributeEval());
    search.put("Chisquared",new ChiSquaredAttributeEval());

    for(String key : search.keySet()) {



        try{
            Ranker attribute_search = new Ranker();
                J48 base = new J48();
            CVParameterSelection ps = new CVParameterSelection();
                ps.setClassifier(base); 
                ps.setNumFolds(5);
                ps.addCVParameter("C 0.1 0.5 5");
                ps.buildClassifier(training_data);

                System.out.println("---------------- " + search.get(key).toString() + " ----------------");

                classifier.setClassifier(ps);                       
            classifier.setEvaluator(search.get(key));
            classifier.setSearch(attribute_search);

                  attsel.setEvaluator(search.get(key));
                  attsel.setSearch(attribute_search);
                  attsel.setInputFormat(training_data);



            Evaluation evaluation = new Evaluation(training_data);
            evaluation.crossValidateModel(ps, training_data, 10, new Random(1));
            System.out.println("\nevaluation ->");          
            System.out.println(evaluation.toSummaryString());
            System.out.println("MAE: " + evaluation.meanAbsoluteError());

        } catch(Exception e) {
            e.printStackTrace();
        }
    }
4

1 回答 1

0

我不确定你是怎么做的。但是您是否尝试过使用网格搜索?

于 2013-06-05T22:00:10.017 回答