当前位置: 首页>>代码示例>>Java>>正文


Java Instances.trainCV方法代码示例

本文整理汇总了Java中weka.core.Instances.trainCV方法的典型用法代码示例。如果您正苦于以下问题:Java Instances.trainCV方法的具体用法?Java Instances.trainCV怎么用?Java Instances.trainCV使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.Instances的用法示例。


在下文中一共展示了Instances.trainCV方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTrainSet

import weka.core.Instances; //导入方法依赖的package包/类
public Instances getTrainSet(int foldNumber, int foldTotal, String fnData) throws Exception {
    // load instances
    Instances data = new Instances(new BufferedReader(new FileReader(fnData)));
    data.setClassIndex(data.numAttributes() - 1);
    Instances trainSet = data.trainCV(foldTotal, foldNumber);

    return trainSet;
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:9,代码来源:CertSVMPredictor.java

示例2: getTestSet

import weka.core.Instances; //导入方法依赖的package包/类
public Instances getTestSet(int foldNumber, int foldTotal, String fnData) throws Exception {
    // load instances
    Instances data = new Instances(new BufferedReader(new FileReader(fnData)));
    data.setClassIndex(data.numAttributes() - 1);
    Instances testSet = data.trainCV(foldTotal, foldNumber);

    return testSet;
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:9,代码来源:CertSVMPredictor.java

示例3: showFolds

import weka.core.Instances; //导入方法依赖的package包/类
/***
	 * <p>Using Feature Selection method to get 10 folds results in the given project</p>
	 * @param path project path
	 * @param sel label means we use the Feature Selection method
	 * @throws Exception 
	 */
	public static void showFolds(String path, int k, int flag) throws Exception{
			
		Instances data1 = DataSource.read(path);
		data1.setClassIndex(data1.numAttributes()-1);
		if(!data1.classAttribute().isNominal()) // in case of noisy data, return
			return;
		
		/** Feature Selection: Correlation */
		CorrelationAttributeEval evall = new CorrelationAttributeEval();
		Ranker ranker = new Ranker();
		AttributeSelection selector = new AttributeSelection();		
		selector.setEvaluator(evall);
		selector.setSearch(ranker);
		selector.setInputFormat(data1);
		data1 = Filter.useFilter(data1, selector);

		/** Randomize and stratify the dataset*/
		data1.randomize(new Random(1)); 	
		data1.stratify(10);	// 10 folds
		
		double[][] matrix = new double[10][7];	
		
		for(int i=0; i<10; i++){ // To calculate the results in each fold
			
			Instances test = data1.testCV(10, i);
			Instances train = data1.trainCV(10, i);
			
			/** SMOTE */
			SMOTE smote = new SMOTE();
			smote.setInputFormat(train);
			train = Filter.useFilter(train, smote);

			/** C4.5 */
			J48 rf = new J48();
//			RandomForest rf = new RandomForest();
//			rf.setNumIterations(300);
			rf.buildClassifier(train);
			
			Evaluation eval = new Evaluation(train);
			eval.evaluateModel(rf, test); 
					
			matrix[i][6] = 1-eval.errorRate();
			
			matrix[i][0] = eval.precision(0);
			
			matrix[i][1] = eval.recall(0);
			
			matrix[i][2] = eval.fMeasure(0);
			
			matrix[i][3] = eval.precision(1);
			
			matrix[i][4] = eval.recall(1);
			
			matrix[i][5] = eval.fMeasure(1);
			
		}
		
		for(int i=0;i<10;i++){
			for(int j=0;j<7;j++){
				System.out.printf("%15.8f", matrix[i][j]);
			}
			System.out.println("");
		}
	}
 
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:71,代码来源:FoldResultsAve.java


注:本文中的weka.core.Instances.trainCV方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。