當前位置: 首頁>>代碼示例>>Java>>正文


Java GainRatioAttributeEval類代碼示例

本文整理匯總了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;
}
 
開發者ID:amineabdaoui,項目名稱:french-sentiment-classification,代碼行數:12,代碼來源:SelectionAttributs.java

示例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();
				
	}
 
開發者ID:Gu-Youngfeng,項目名稱:CraTer,代碼行數:50,代碼來源:FeatureSelectionAve.java


注:本文中的weka.attributeSelection.GainRatioAttributeEval類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。