protected static void attSelection_w(Instances data) throws Exception {
AttributeSelection fs = new AttributeSelection();
WrapperSubsetEval wrapper = new WrapperSubsetEval();
wrapper.buildEvaluator(data);
wrapper.setClassifier(new RandomForest());
wrapper.setFolds(10);
wrapper.setThreshold(0.001);
fs.SelectAttributes(data);
fs.setEvaluator(wrapper);
fs.setSearch(new BestFirst());
System.out.println(fs.toResultsString());
}
以上是我使用随机森林+ bestfirst搜索进行基于包装器的属性选择的代码。但是,这会以某种方式使用cfs吐出结果,如下所示。
Search Method:
Greedy Stepwise (forwards).
Start set: no attributes
Merit of best subset found: 0.287
Attribute Subset Evaluator (supervised, Class (nominal): 9 class):
CFS Subset Evaluator
Including locally predictive attributes
在整个班级中没有其他使用CFS的代码,我几乎被卡住了......我将不胜感激任何帮助。谢谢!
答案 0 :(得分:0)
您只是颠倒了顺序并获得了默认方法,正确的顺序是首先设置参数,然后调用选择:
//first
fs.setEvaluator(wrapper);
fs.setSearch(new BestFirst());
//then
fs.SelectAttributes(data);
答案 1 :(得分:0)
只需设置类索引并在创建实例数据后添加此行
data.setClassIndex(data.numAttributes() - 1);
我检查过,它工作正常。