本文整理汇总了Java中weka.attributeSelection.GainRatioAttributeEval类的典型用法代码示例。如果您正苦于以下问题:Java GainRatioAttributeEval类的具体用法?Java GainRatioAttributeEval怎么用?Java GainRatioAttributeEval使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GainRatioAttributeEval类属于weka.attributeSelection包,在下文中一共展示了GainRatioAttributeEval类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GainRatioAttributeEval
import weka.attributeSelection.GainRatioAttributeEval; //导入依赖的package包/类
public static AttributeSelection GainRatioAttributeEval(Instances data, int n) throws Exception{
AttributeSelection filter = new AttributeSelection();
GainRatioAttributeEval evaluator = new GainRatioAttributeEval();
filter.setEvaluator(evaluator);
Ranker search = new Ranker();
search.setNumToSelect(n);
filter.setSearch(search);
filter.setInputFormat(data);
return filter;
}
示例2: getEvalResultbyGainRatio
import weka.attributeSelection.GainRatioAttributeEval; //导入依赖的package包/类
/***
* <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
* <p>Use C4.5 and <b>SMOTE</b>, combined with <b>Information Gain Ratio</b> to classify the dataset.</p>
* @param path dataset path
* @throws Exception
*/
public static void getEvalResultbyGainRatio(String path, int index) throws Exception{
Instances ins = DataSource.read(path);
int numAttr = ins.numAttributes();
ins.setClassIndex(numAttr - 1);
/**information gain ratio filter to process the whole dataset first*/
GainRatioAttributeEval evall = new GainRatioAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(ins);
ins = Filter.useFilter(ins, selector);
SMOTE smote = new SMOTE();
smote.setInputFormat(ins);
/** classifiers setting*/
J48 j48 = new J48();
// j48.setConfidenceFactor(0.4f);
j48.buildClassifier(ins);
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(j48);
fc.setFilter(smote);
Evaluation eval = new Evaluation(ins);
eval.crossValidateModel(fc, ins, 10, new Random(1));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
// System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
results[index][0] = eval.precision(0);
results[index][1] = eval.recall(0);
results[index][2] = eval.fMeasure(0);
results[index][3] = eval.precision(1);
results[index][4] = eval.recall(1);
results[index][5] = eval.fMeasure(1);
results[index][6] = 1-eval.errorRate();
}