参数优化&与Weka一起选择

时间:2013-03-02 09:21:48

标签: machine-learning classification weka text-mining

我想在J48中设置-C参数,并运行三个存储在哈希表中的特征选择算法。我想比较三者的性能如准确度,真阳性,真阴性,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();
        }
    }

1 个答案:

答案 0 :(得分:0)

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