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


Java Classifier.buildClassifier方法代碼示例

本文整理匯總了Java中weka.classifiers.Classifier.buildClassifier方法的典型用法代碼示例。如果您正苦於以下問題:Java Classifier.buildClassifier方法的具體用法?Java Classifier.buildClassifier怎麽用?Java Classifier.buildClassifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.classifiers.Classifier的用法示例。


在下文中一共展示了Classifier.buildClassifier方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: train

import weka.classifiers.Classifier; //導入方法依賴的package包/類
private void train(String name) {
	try {
		Classifier randomForest = new RandomForest();

		ConverterUtils.DataSource source = new ConverterUtils.DataSource(FOLDER + name);
		dataSet = source.getDataSet();

		dataSet.setClassIndex(dataSet.numAttributes() - 1);
		randomForest.buildClassifier(dataSet);

		classifier = randomForest;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:igr,項目名稱:parlo,代碼行數:16,代碼來源:SentenceClassifier.java

示例2: train

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public void train() {
	try {
		Classifier randomForest = new RandomForest();

		ConverterUtils.DataSource source = new ConverterUtils.DataSource(FOLDER + "question-classifier.arff");
		dataSet = source.getDataSet();

		dataSet.setClassIndex(dataSet.numAttributes() - 1);
		randomForest.buildClassifier(dataSet);

		classifier = randomForest;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:igr,項目名稱:parlo,代碼行數:16,代碼來源:QuestionClassifier.java

示例3: evaluate

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public static void evaluate(Classifier clf, Instances data, double minPerfomance)
    throws Exception {
  Instances[] split = TestUtil.splitTrainTest(data);

  Instances train = split[0];
  Instances test = split[1];

  clf.buildClassifier(train);
  Evaluation trainEval = new Evaluation(train);
  trainEval.evaluateModel(clf, train);

  Evaluation testEval = new Evaluation(train);
  testEval.evaluateModel(clf, test);

  final double testPctCorrect = testEval.pctCorrect();
  final double trainPctCorrect = trainEval.pctCorrect();

  log.info("Train: {}, Test: {}", trainPctCorrect, testPctCorrect);
  boolean success =
      testPctCorrect > minPerfomance && trainPctCorrect > minPerfomance;
  Assert.assertTrue(success);
}
 
開發者ID:Waikato,項目名稱:wekaDeeplearning4j,代碼行數:23,代碼來源:StabilityTest.java

示例4: holdout

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Perform simple holdout with a given percentage
 *
 * @param clf Classifier
 * @param data Full dataset
 * @param p Split percentage
 * @throws Exception
 */
public static void holdout(Classifier clf, Instances data, double p) throws Exception {
  Instances[] split = splitTrainTest(data, p);

  Instances train = split[0];
  Instances test = split[1];

  clf.buildClassifier(train);
  Evaluation trainEval = new Evaluation(train);
  trainEval.evaluateModel(clf, train);
  logger.info("Weka Train Evaluation:");
  logger.info(trainEval.toSummaryString());
  if (!data.classAttribute().isNumeric()) {
    logger.info(trainEval.toMatrixString());
  }

  Evaluation testEval = new Evaluation(train);
  logger.info("Weka Test Evaluation:");
  testEval.evaluateModel(clf, test);
  logger.info(testEval.toSummaryString());
  if (!data.classAttribute().isNumeric()) {
    logger.info(testEval.toMatrixString());
  }
}
 
開發者ID:Waikato,項目名稱:wekaDeeplearning4j,代碼行數:32,代碼來源:TestUtil.java

示例5: train

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public void train(String datasetFilename, boolean serialise)
{
    String[] lines = Utils.readLines(datasetFilename);
    int i = 1; // skip legend
    try
    {            
        for(i = 1; i < lines.length; i++) // skip legend
        {
            dataset.add(createFeatureVector(lines[i].split(","), true));
        }
        model = (Classifier) new LinearRegression();
        ((LinearRegression)model).setRidge(1.0e-10);
        model.buildClassifier(dataset);
        if(serialise)
        {                
            SerializationHelper.write(new FileOutputStream(modelFilename), model);
        }
    }
    catch(Exception e)
    {
        System.err.println("Error in line " + i + ": " + lines[i]);
        e.printStackTrace();
    }
}
 
開發者ID:sinantie,項目名稱:Generator,代碼行數:25,代碼來源:LinearRegressionWekaWrapper.java

示例6: training

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public void training(double[][] trainFeatures) throws Exception {
	/**
	 * Need to be replaced
	 */
	//How to preprocess trainFeatures into inst


	BufferedReader reader = new BufferedReader(
			new FileReader("/Users/karl/Work/database/forsimpletest/1.arff"));
	Instances inst = new Instances(reader);
	reader.close();
	inst.setClassIndex(inst.numAttributes() - 1);

	//Init classifier
	Classifier cls = new J48();
	cls.buildClassifier(inst);

	// serialize model
	weka.core.SerializationHelper.write(modelFile, cls);
}
 
開發者ID:KangCai,項目名稱:AudioProcessingBox,代碼行數:21,代碼來源:BasicClassification.java

示例7: getJ48Model

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Weka implementation of C4.5
 */
public Classifier getJ48Model() throws Exception {
    Classifier model = new J48();
    model.buildClassifier(instances);

    return model;
}
 
開發者ID:GeorgiMateev,項目名稱:twitter-user-gender-classification,代碼行數:10,代碼來源:Train.java

示例8: getSMO

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Weka implementation of SVM
 */
public Classifier getSMO() throws Exception {
    Classifier model = new SMO();
    ((PolyKernel) ((SMO) model).getKernel()).setExponent(2);
    model.buildClassifier(instances);

    return model;
}
 
開發者ID:GeorgiMateev,項目名稱:twitter-user-gender-classification,代碼行數:11,代碼來源:Train.java

示例9: getIBk

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Weka implementation of kNN
 */
public Classifier getIBk() throws Exception {
    Classifier model = new IBk();
    model.buildClassifier(instances);

    return model;
}
 
開發者ID:GeorgiMateev,項目名稱:twitter-user-gender-classification,代碼行數:10,代碼來源:Train.java

示例10: getNaiveBayes

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public Classifier getNaiveBayes() throws Exception {
    Classifier model = new NaiveBayes();
    model.buildClassifier(instances);

    return model;
}
 
開發者ID:GeorgiMateev,項目名稱:twitter-user-gender-classification,代碼行數:7,代碼來源:Train.java

示例11: trainClassifier

import weka.classifiers.Classifier; //導入方法依賴的package包/類
@TimeThis(task="train", category=TimerCategory.EXTERNAL)
protected void trainClassifier(ProcessingContext<Corpus> ctx, Classifier classifier, IdentifiedInstances<Element> trainingSet) throws Exception {
	getLogger(ctx).info("training classifier");
	classifier.buildClassifier(trainingSet);
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:6,代碼來源:WekaTrain.java

示例12: manyEvaluations

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public String manyEvaluations(Instances dataSet,Classifier classifier) throws Exception {

        String saida="";
        Instances iTeste;
        Instances iTreinamento;
        Instances instances = dataSet.resample(new Random(1));

        for(int i=2;i<20;i++){

            for (int j=1;j<i;j++){

                iTeste = instances.testCV(i, j);
                iTreinamento = instances.trainCV(i, j);
                classifier.buildClassifier(iTreinamento);
                super.evaluateModel(classifier,iTeste);
                saida+="\nTeste: "+iTeste.numInstances()+" , Treinamento: "+iTreinamento.numInstances();
                saida+="\nTaxa de Erro: "+ super.errorRate()+"\n";

            }

        }


        return saida;
    }
 
開發者ID:K-weka,項目名稱:k-weka,代碼行數:26,代碼來源:CustomEvaluation.java

示例13: main

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

		BufferedReader reader = new BufferedReader(new FileReader("model/comments.arff"));
		Instances data = new Instances(reader);
		data.setClassIndex(data.numAttributes() - 1);

		reader.close();
		
		
		
	//	Classifier classifier = new J48();
		
		Classifier classifier = new NaiveBayesMultinomialText();
		classifier.buildClassifier(data);
		
		String testMessage = "Spencer, my tone? You sir are political correctness gone mad!";
				
		double[] ret = classifyMessage(classifier, data, testMessage);
		System.out.println(ret[0]+ ":" + ret[1]);
		
		
//		Classifier jbClassifier = new J48();
//      // Filter instance.
//      StringToWordVector m_Filter = new StringToWordVector();
//      m_Filter.setInputFormat(data);
//
//      // Generate word counts from the training data.
//      Instances filteredData  = Filter.useFilter(data, m_Filter);
//
//      // Rebuild classifier.
//      jbClassifier.buildClassifier(filteredData);
//      ret = classifyMessage(jbClassifier,m_Filter, data, testMessage);
//      System.out.println(ret[0]+ ":" + ret[1]);
	
      
	}
 
開發者ID:SOBotics,項目名稱:SOCVFinder,代碼行數:37,代碼來源:TestWekaClassifier.java

示例14: getTrainTestPredictions

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Generate a bunch of predictions ready for processing, by performing a
 * evaluation on a test set after training on the given training set.
 * 
 * @param classifier the Classifier to evaluate
 * @param train the training dataset
 * @param test the test dataset
 * @exception Exception if an error occurs
 */
public ArrayList<Prediction> getTrainTestPredictions(Classifier classifier,
  Instances train, Instances test) throws Exception {

  classifier.buildClassifier(train);
  return getTestPredictions(classifier, test);
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:16,代碼來源:EvaluationUtils.java


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