本文整理匯總了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();
}