使用Java中的包装器和RandomForest分类器进行功能选择时出错

时间:2015-12-07 00:41:14

标签: java weka

我正在使用RandomForest分类器进行包装器功能选择,并且该代码应该生成具有较少或不需要的功能的新数据集:

import weka.attributeSelection.*;
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.supervised.attribute.AttributeSelection;
import weka.core.converters.ArffSaver;
import java.io.File;
import weka.core.converters.ConverterUtils.DataSource;
import weka.classifiers.trees.*;


public class feature_selection
{
    public static void main(String args[]) throws Exception{
        //load dataset
        DataSource source = new DataSource("/ProjectTraining&TestingData/project/EECS738_Train_Project.arff");
        Instances dataset = source.getDataSet();
        dataset.setClassIndex(0);

        AttributeSelection filter = new AttributeSelection();
        WrapperSubsetEval wrapper = new WrapperSubsetEval();
        BestFirst search = new BestFirst();
        RandomForest base=new RandomForest();

        wrapper.setClassifier(base);
        filter.setEvaluator( wrapper);
        filter.setSearch(search);
        filter.setInputFormat(dataset);

        //apply
        Instances newData = Filter.useFilter(dataset, filter);
        //save
        ArffSaver saver = new ArffSaver();
        saver.setInstances(newData);
        saver.setFile(new File("/ProjectTraining&TestingData/project/EECS738_Train_ProjectResult111.arff"));
        saver.writeBatch();
    }
}

但我收到以下错误:

Cannot build model (only class attribute present in data!), using ZeroR model instead!

0 个答案:

没有答案