【发布时间】:2014-02-03 15:11:36
【问题描述】:
我是 Weka 的新手,我有 2 类数据要分类。我可以使用权重(单词出现、TFIDF 或单词存在)对其进行分类。我想使用 Weka 中集成的特征选择机制来提高分类器的准确性,如下所示:
BufferedReader trainReader = new BufferedReader(new FileReader(dataSource));
trainInsts = new Instances(trainReader);
trainInsts.setClassIndex(trainInsts.numAttributes() - 1);
// I am using the filter to convert the data from string to numeric
StringToWordVector STWfilter = new StringToWordVector();
FilteredClassifier model = new FilteredClassifier();
model.setFilter(STWfilter);
STWfilter.setOutputWordCounts(true);
int n = 400; // number of features to select
AttributeSelection attributeSelection = new AttributeSelection();
ranker = new Ranker();
ranker.setNumToSelect(n);
infoGainAttributeEval = new InfoGainAttributeEval();
attributeSelection.setEvaluator(infoGainAttributeEval);
attributeSelection.setSearch(ranker);
attributeSelection.setInputFormat(trainInsts);
trainInsts = Filter.useFilter(trainInsts, attributeSelection);
Evaluation eval = new Evaluation(trainInsts);
eval.crossValidateModel(model, trainInsts, folds, new Random(1));
这很有效,我可以看到使用标准加权方法(例如(单词出现))略有改进。我不确定我所做的是否正确。因为我觉得特征选择方法和加权方法是一样的。我还必须给出我应该拥有的“n”个功能吗?这会显着影响分类器的结果,如何设置,例如当我有 3000 个实例时,我应该选择多少个特征? Weka 中还有什么方法可以获取我的数据中的特征(单词)数量吗?例如,对于 2000 个实例,最佳准确度是 n=400 。
有没有cmets?
提前致谢
【问题讨论】:
标签: weka