简体   繁体   中英

Parameter Optimization & Attibute Selection with Weka

I want to set the -C Parameter in J48 and run three feature selection algorithms which are stored inside a hashtable. I want to compare the performance of the three like accuracy, true positive, true negative, F1 etc. But when I run all the feature selection algorithms, they return me the same output.... Am I doing something wrong?

    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();
        }
    }

I am not sure how you are doing it. But have you tried using Grid Search?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM