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


Java FilteredClassifier.setFilter方法代码示例

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


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

示例1: LearnNaiveBays

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
@Override
public void LearnNaiveBays() throws Exception 
{
	trainedData.setClassIndex(trainedData.numAttributes()-1);
       filter=new StringToWordVector();
       classifier=new FilteredClassifier();
       classifier.setFilter(filter);
       classifier.setClassifier(new NaiveBayes());
       classifier.buildClassifier(trainedData);
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:11,代码来源:ExtractClassificationTextNaiveBaysImpl.java

示例2: buildFilteredClassifier

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
public void buildFilteredClassifier(){
	rf = new RandomForest();
	Remove rm = new Remove();
	rm.setAttributeIndices("1");
	FilteredClassifier fc = new FilteredClassifier();
	fc.setFilter(rm);
	fc.setClassifier(rf);
	try{
		fc.buildClassifier(weather);
		for (int i = 0; i < weather.numInstances(); i++){
			double pred = fc.classifyInstance(weather.instance(i));
			System.out.print("given value: " + weather.classAttribute().value((int) weather.instance(i).classValue()));
			System.out.println("---predicted value: " + weather.classAttribute().value((int) pred));
		}
	} catch (Exception e) {
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:WekaFilteredClassifierTest.java

示例3: classify

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * Classifies function wise test instances in the associated with the names labels mentioned in the arraylist passed as the argument.
 *
 * @param list - labels of instances contained in the test set that need to be classified.
 * @return TreeMap containing the instance labels and the associated classification results.
 * @throws ClassificationFailedException
 */
@Override
public LinkedHashMap<String, String> classify(LinkedList<String> list) throws ClassificationFailedException {
    output = new LinkedHashMap<String, String>();
    J48 j48 = new J48();
    Remove rm = new Remove();
    rm.setAttributeIndices("1");
    FilteredClassifier fc = new FilteredClassifier();
    fc.setFilter(rm);
    fc.setClassifier(j48);
    try {
        fc.buildClassifier(trainSet);
        for (int i = 0; i < testSet.numInstances(); i++) {
            double pred = fc.classifyInstance(testSet.instance(i));
            if (list.isEmpty()) {
                output.put(String.valueOf(i + 1), testSet.classAttribute().value((int) pred));
            } else {
                output.put(list.get(i), testSet.classAttribute().value((int) pred));
            }
        }
    } catch (Exception ex) {
        throw new ClassificationFailedException();
    }
    return output;
}
 
开发者ID:sunimalr,项目名称:vimarsha,代码行数:32,代码来源:FunctionWiseClassifier.java

示例4: getEvalResultbySMOTE

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的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> to classify the dataset.</p>
	 * @param path dataset path
	 * @throws Exception
	 */
	public static void getEvalResultbySMOTE(String path, int index) throws Exception{
		
		Instances ins = DataSource.read(path);
		int numAttr = ins.numAttributes();
		ins.setClassIndex(numAttr - 1);
		
		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,代码行数:40,代码来源:ImbalanceProcessingAve.java

示例5: afterPropertiesSet

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * Loads the training data as configured in {@link #dataConfig} and trains a
 * 3-gram SVM classifier.
 */
@Override
public void afterPropertiesSet() throws Exception {
	this.trainingData = svmTrainer.train();
	StringToWordVector stwvFilter = createFilter(this.trainingData);
	// Instances filterdInstances = Filter.useFilter(data, stwv);

	LibSVM svm = new LibSVM();
	svm.setKernelType(new SelectedTag(0, LibSVM.TAGS_KERNELTYPE));
	svm.setSVMType(new SelectedTag(0, LibSVM.TAGS_SVMTYPE));
	svm.setProbabilityEstimates(true);
	// svm.buildClassifier(filterdInstances);

	FilteredClassifier filteredClassifier = new FilteredClassifier();
	filteredClassifier.setFilter(stwvFilter);
	filteredClassifier.setClassifier(svm);
	filteredClassifier.buildClassifier(this.trainingData);
	this.classifier = filteredClassifier;

	// predict("nice cool amazing awesome beautiful");
	// predict("this movie is simply awesome");
	// predict("its very bad");
	// predict("Not that great");
}
 
开发者ID:venilnoronha,项目名称:movie-rating-prediction,代码行数:28,代码来源:SVMPredictorImpl.java

示例6: testFilteredClassifier

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * Test filtered classifier using PyScriptFilter with
 * PyScriptClassifier. Just seeing if no exceptions
 * are thrown here.
 */
@Test
public void testFilteredClassifier() throws Exception {
	DataSource ds = new DataSource("datasets/iris.arff");
	Instances data = ds.getDataSet();
	data.setClassIndex( data.numAttributes() - 1 );
	
	FilteredClassifier fs = new FilteredClassifier();
	
	PyScriptClassifier pyScriptClassifier = new PyScriptClassifier();
	pyScriptClassifier.setPythonFile(new File("scripts/scikit-rf.py"));
	pyScriptClassifier.setArguments("num_trees=10;");
	
	PyScriptFilter filter = new PyScriptFilter();
	filter.setPythonFile(new File("scripts/standardise.py"));

	fs.setClassifier(pyScriptClassifier);
	fs.setFilter(filter);
	
	fs.buildClassifier(data);
	fs.distributionsForInstances(data);
}
 
开发者ID:christopher-beckham,项目名称:weka-pyscript,代码行数:27,代码来源:PyScriptFilterTest.java

示例7: generateAndWriteFullModel

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * Generate the model with all data and write it with the appropriate filters.
 *
 * @param instances as returned from {@link WekaUtils#createInstances(String)}
 * @throws Exception
 */
private void generateAndWriteFullModel(Instances instances) throws Exception {
  StringToWordVector stringToWordVector = getStringToWordVectorFilter(instances);
  Instances stringsReplacedData = Filter.useFilter(instances, stringToWordVector);
  Instances resampled = dumbResample(stringsReplacedData);
  Remove removeFilter = getRemoveFilter(stringsReplacedData);
  LibSVM svmForOut = new LibSVM();
  svmForOut.setCost(config.getSvmCost().get(0));
  svmForOut.setGamma(config.getSvmGamma().get(0));
  FilteredClassifier filteredClassifierForOut = new FilteredClassifier();
  filteredClassifierForOut.setClassifier(svmForOut);
  filteredClassifierForOut.setFilter(removeFilter);
  filteredClassifierForOut.buildClassifier(resampled);
  weka.core.SerializationHelper.write(config.getOutputDir() + "/svm_model_c_" + config.getSvmCost().get(0) + "_gamma_" + config.getSvmGamma().get(0) + ".model", filteredClassifierForOut);
  weka.core.SerializationHelper.write(config.getOutputDir() + "/string_filter_c_" + config.getSvmCost().get(0) + "_gamma_" + config.getSvmGamma().get(0) + ".model", stringToWordVector);
}
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:22,代码来源:WekaLearner.java

示例8: learn

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * This method trains the classifier on the loaded dataset.
 */
public void learn() {
	try {
		trainData.setClassIndex(0);
		filter = new StringToWordVector();
		filter.setAttributeIndices("last");
		classifier = new FilteredClassifier();
		classifier.setFilter(filter);
		classifier.setClassifier(new NaiveBayes());
		
		
		classifier.buildClassifier(trainData);
		// Uncomment to see the classifier
		System.out.println("===== Training on filtered (training) dataset =====");
		//System.out.println(classifier);
	} catch (Exception e) {
		System.out.println("Problem found when training");
	}
}
 
开发者ID:amplia,项目名称:weka-classifier-examples,代码行数:22,代码来源:Learner.java

示例9: classify

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * Classifies whole program test instances,
 *
 * @return String containing the classification result of the evaluated program's dataset.
 * @throws ClassificationFailedException
 */
@Override
public Object classify() throws ClassificationFailedException {
    J48 j48 = new J48();
    Remove rm = new Remove();
    String output = null;
    rm.setAttributeIndices("1");
    FilteredClassifier fc = new FilteredClassifier();
    fc.setFilter(rm);
    fc.setClassifier(j48);
    try {
        fc.buildClassifier(trainSet);
        this.treeModel = j48.toString();
        double pred = fc.classifyInstance(testSet.instance(0));
        output = testSet.classAttribute().value((int) pred);
        classificationResult = output;
    } catch (Exception ex) {
        throw new ClassificationFailedException();
    }
    return output;
}
 
开发者ID:sunimalr,项目名称:vimarsha,代码行数:27,代码来源:WholeProgramClassifier.java

示例10: classify

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/**
 * Classifies Timesliced test data instances.
 *
 * @return Resulting linked list with timelsiced classification results.
 * @throws ClassificationFailedException
 */
@Override
public Object classify() throws ClassificationFailedException {
    output = new LinkedList<String>();
    J48 j48 = new J48();
    Remove rm = new Remove();
    rm.setAttributeIndices("1");
    FilteredClassifier fc = new FilteredClassifier();
    fc.setFilter(rm);
    fc.setClassifier(j48);
    try {
        fc.buildClassifier(trainSet);


        for (int i = 0; i < testSet.numInstances(); i++) {
            //System.out.println(testSet.instance(i));
            double pred = fc.classifyInstance(testSet.instance(i));
            output.add(testSet.classAttribute().value((int) pred));
        }
    } catch (Exception ex) {
        System.out.println(ex.toString());
        throw new ClassificationFailedException();
    }
    return output;
}
 
开发者ID:sunimalr,项目名称:vimarsha,代码行数:31,代码来源:TimeslicedClassifier.java

示例11: getEvalResultbyResampling

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
/***
	 * <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
	 * <p>Use C4.5 and <b>Resampling</b> to classify the dataset.</p>
	 * @param path dataset path
	 * @throws Exception
	 */
	public static void getEvalResultbyResampling(String path, int index) throws Exception{
		
		Instances ins = DataSource.read(path);
		int numAttr = ins.numAttributes();
		ins.setClassIndex(numAttr - 1);
		
		Resample resample = new Resample();
		resample.setInputFormat(ins);
		
		/** classifiers setting*/
		J48 j48 = new J48();
//		j48.setConfidenceFactor(0.4f);
		j48.buildClassifier(ins);

		FilteredClassifier fc = new FilteredClassifier();
		fc.setClassifier(j48);
		fc.setFilter(resample);
			
		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,代码行数:40,代码来源:ImbalanceProcessingAve.java

示例12: getEvalResultbyDefault

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的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> to classify the dataset.</p>
	 * @param path dataset path
	 * @throws Exception
	 */
	public static void getEvalResultbyDefault(String path, int index) throws Exception{
		
		Instances ins = DataSource.read(path);
		int numAttr = ins.numAttributes();
		ins.setClassIndex(numAttr - 1);
		
		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,代码行数:40,代码来源:FeatureSelectionAve.java

示例13: createClassifier

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
private Classifier createClassifier() throws Exception {
   	Classifier baseClassifier = Classifier.forName(getAlgorithm(), getClassifierOptions());
   	FilteredClassifier result = new FilteredClassifier();
   	result.setClassifier(baseClassifier);
   	Remove filter = new Remove();
   	filter.setAttributeIndicesArray(new int[] { 0 });
   	result.setFilter(filter);
   	return result;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:10,代码来源:WekaTrain.java

示例14: LearnRandomForest

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
@Override
public void LearnRandomForest() throws Exception 
{
	   trainedData.setClassIndex(trainedData.numAttributes()-1);
        filter=new StringToWordVector();
        classifier=new FilteredClassifier();
        classifier.setFilter(filter);
        classifier.setClassifier(new RandomForest());
        classifier.buildClassifier(trainedData);
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:11,代码来源:ExtractClassificationTextRandomForestImpl.java

示例15: LearnKNN

import weka.classifiers.meta.FilteredClassifier; //导入方法依赖的package包/类
@Override
public void LearnKNN() throws Exception {
	trainedData.setClassIndex(trainedData.numAttributes()-1);
       filter=new StringToWordVector();
       classifier=new FilteredClassifier();
       classifier.setFilter(filter);
       classifier.setClassifier(new IBk());
       classifier.buildClassifier(trainedData);
	
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:11,代码来源:ExtractClassificationTextKNNImpl.java


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