Example usage for weka.classifiers Evaluation Evaluation

List of usage examples for weka.classifiers Evaluation Evaluation

Introduction

In this page you can find the example usage for weka.classifiers Evaluation Evaluation.

Prototype

public Evaluation(Instances data) throws Exception 

Source Link

Usage

From source file:newclassifier.NewClassifier.java

public void givenTestSet(String path) throws Exception {
    Instances test = DataSource.read(path);
    test.setClassIndex(test.numAttributes() - 1);

    cls.buildClassifier(data);/*  w  ww .j  av  a 2 s  . c o m*/

    Evaluation eval = new Evaluation(data);
    eval.evaluateModel(cls, test);
    System.out.println(eval.toSummaryString("\nResults\n======\n", false));
    System.out.println(eval.toClassDetailsString());
    System.out.println(eval.toMatrixString());
}

From source file:news.classifier.WekaLearner.java

public void setTrainingData(String fileLocation) throws Exception {
    wTrainingSet = ConverterUtils.DataSource.read(fileLocation);
    wClassIndex = wTrainingSet.numAttributes() - 1;
    wTrainingSet.setClassIndex(wClassIndex);
    wEvaluation = new Evaluation(wTrainingSet);
}

From source file:news.classifier.WekaLearner.java

public String fullTrainingEvaluation() throws Exception {
    wClassifier.buildClassifier(wTrainingSet);

    wEvaluation = new Evaluation(wTrainingSet);
    wEvaluation.evaluateModel(wClassifier, wTrainingSet);

    return wClassifier.toString()
            + wEvaluation.toSummaryString("\nHasil evaluasi dengan full-trainning:\n", false);
}

From source file:news.classifier.WekaLearner.java

public List<Prediction> fullTrainingEvaluation(Instances testData) throws Exception {
    wClassifier.buildClassifier(wTrainingSet);

    wEvaluation = new Evaluation(wTrainingSet);
    wEvaluation.evaluateModel(wClassifier, testData);

    return wEvaluation.predictions();
}

From source file:news.classifier.WekaLearner.java

public String crossValidationEvaluation(int fold) throws Exception {
    wEvaluation = new Evaluation(wTrainingSet);
    wEvaluation.crossValidateModel(wClassifier, wTrainingSet, fold, new Random(1));

    return wClassifier.toString() + wEvaluation.toSummaryString(
            "\nHasil evaluasi dengan cross-validation " + Integer.toString(fold) + "-fold:\n", false);
}

From source file:newsclassifier.NewsClassifier.java

public void CrossValidation(Classifier cls, int n) throws Exception {
    data.setClassIndex(0);/* www  .ja  va  2 s.  c o m*/
    Evaluation eval = new Evaluation(data);
    cls.buildClassifier(data);
    eval.crossValidateModel(cls, data, n, new Random(1));
    System.out.println(eval.toSummaryString("Results", false));
    //System.out.println(eval.toClassDetailsString());
    //System.out.println(eval.toMatrixString());
}

From source file:nl.detoren.ijc.neural.Voorspeller.java

License:Open Source License

/**
 * Evalueer trainingsdata/*from   w  w w.  j a  v  a 2 s.c om*/
 *
 * @param data
 * @return
 * @throws Exception
 */
private Evaluation evaluateTrainingData(Instances data) throws Exception {
    mlp.buildClassifier(data);
    Evaluation eval = new Evaluation(data);
    eval.evaluateModel(mlp, data);
    logger.log(Level.INFO, eval.toSummaryString(true));
    return eval;
}

From source file:nl.uva.expose.classification.WekaClassification.java

private void classifierTrainer(Instances trainData) throws Exception {
    trainData.setClassIndex(0);//w  w  w.  java  2s. c  o  m
    //        classifier.setFilter(filter);
    classifier.setClassifier(new NaiveBayes());
    classifier.buildClassifier(trainData);
    Evaluation eval = new Evaluation(trainData);
    eval.crossValidateModel(classifier, trainData, 5, new Random(1));
    System.out.println(eval.toSummaryString());
    System.out.println(eval.toClassDetailsString());
    System.out.println("===== Evaluating on filtered (training) dataset done =====");
    System.out.println("\n\nClassifier model:\n\n" + classifier);
}

From source file:OAT.trading.classification.Weka.java

License:Open Source License

@Override
public Prediction predict(InputSample input) {
    if (classifier == null) {
        log(Level.WARNING, "null classifier");
        return null;
    }/*from w  w w .jav  a  2s . c  o m*/

    Instances data = getInstances(input);

    if (data == null) {
        log(Level.WARNING, "null data");
        return null;
    }

    if (!isCrossValidating()) {
        if (isLoggable(Level.FINER)) {
            log(Level.FINER, data.toString());
        }
    }

    try {
        double output = new Evaluation(data).evaluateModelOnce(classifier, data.firstInstance());

        return Prediction.valueOf(output < 0.5 ? -1 : 1);
    } catch (Exception ex) {
        log(Level.SEVERE, null, ex);
    }

    return null;
}

From source file:old.CFS.java

/**
 * uses the meta-classifier/*from w ww .j  av  a  2s.  co m*/
 */
protected static void useClassifier(Instances data) throws Exception {
    System.out.println("\n1. Meta-classfier");
    AttributeSelectedClassifier classifier = new AttributeSelectedClassifier();
    ChiSquaredAttributeEval eval = new ChiSquaredAttributeEval();
    Ranker search = new Ranker();
    search.setThreshold(-1.7976931348623157E308);
    search.setNumToSelect(1000);
    J48 base = new J48();
    classifier.setClassifier(base);
    classifier.setEvaluator(eval);
    classifier.setSearch(search);
    Evaluation evaluation = new Evaluation(data);
    evaluation.crossValidateModel(classifier, data, 10, new Random(1));
    System.out.println(evaluation.toSummaryString());
}