0

我尝试使用 WrapperSubsetEval 在 weka 中进行特征选择。它似乎有效,但仅将类属性作为选定功能返回。请帮忙,谢谢!

weka.attributeSelection.AttributeSelection attsel = new weka.attributeSelection.AttributeSelection();

        WrapperSubsetEval eval = new WrapperSubsetEval();
        BestFirst search = new BestFirst();
        String[]  optionsSearch = null;
        String[]  optionsEval = null;
        String[] optionsBase = null;
        try {
            optionsSearch = weka.core.Utils.splitOptions("-D 1 -N 5");
            search.setOptions(optionsSearch);



            LibSVM base = new LibSVM();
            optionsBase = weka.core.Utils.splitOptions("-S 4");
            base.setOptions(optionsBase);

            optionsEval = weka.core.Utils.splitOptions("");
            eval.setOptions(optionsEval);
            eval.setClassifier(base);
            eval.setFolds(5);

            attsel.setEvaluator(eval);
            attsel.setSearch(search);
            dataTrain.setClassIndex(dataTrain.numAttributes() -1);
            attsel.SelectAttributes(dataTrain);
            idx.add( attsel.selectedAttributes() );
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
4

0 回答 0