Search in sources :

Example 1 with Evaluation

use of weka.classifiers.Evaluation in project dkpro-tc by dkpro.

the class WekaResultsTest method testWekaResultsSingleLabel.

@Test
public void testWekaResultsSingleLabel() throws Exception {
    SMO cl = new SMO();
    Instances testData = WekaUtils.makeOutcomeClassesCompatible(singleLabelTrainData, singleLabelTestData, false);
    Instances trainData = WekaUtils.removeInstanceId(singleLabelTrainData, false);
    testData = WekaUtils.removeInstanceId(testData, false);
    cl.buildClassifier(trainData);
    Evaluation eval = WekaUtils.getEvaluationSinglelabel(cl, trainData, testData);
    assertEquals(7.0, eval.correct(), 0.01);
}
Also used : Instances(weka.core.Instances) Evaluation(weka.classifiers.Evaluation) SMO(weka.classifiers.functions.SMO) Test(org.junit.Test)

Example 2 with Evaluation

use of weka.classifiers.Evaluation in project dkpro-tc by dkpro.

the class WekaUtils method getEvaluationSinglelabel.

/**
 * Evaluates a given single-label classifier on given train and test sets.
 *
 * @param cl
 *            classifier
 * @param trainData
 *            weka training instances
 * @param testData
 *            weka test instances
 * @return Evaluation object
 * @throws Exception
 *             in case of errors
 */
public static Evaluation getEvaluationSinglelabel(Classifier cl, Instances trainData, Instances testData) throws Exception {
    Evaluation eval = new Evaluation(trainData);
    eval.evaluateModel(cl, testData);
    return eval;
}
Also used : Evaluation(weka.classifiers.Evaluation) ASEvaluation(weka.attributeSelection.ASEvaluation)

Example 3 with Evaluation

use of weka.classifiers.Evaluation in project dkpro-tc by dkpro.

the class WekaArffTest method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    File train = new File("src/main/resources/arff/manyInstances/train.arff.gz");
    File test = new File("src/main/resources/arff/manyInstances/test.arff.gz");
    Instances trainData = WekaUtils.getInstances(train, false);
    Instances testData = WekaUtils.getInstances(test, false);
    Classifier cl = new NaiveBayes();
    // no problems until here
    Evaluation eval = new Evaluation(trainData);
    eval.evaluateModel(cl, testData);
}
Also used : Instances(weka.core.Instances) NaiveBayes(weka.classifiers.bayes.NaiveBayes) Evaluation(weka.classifiers.Evaluation) Classifier(weka.classifiers.Classifier) File(java.io.File)

Example 4 with Evaluation

use of weka.classifiers.Evaluation in project dkpro-tc by dkpro.

the class WekaResultsTest method testWekaResultsRegression.

@Test
public void testWekaResultsRegression() throws Exception {
    SMOreg cl = new SMOreg();
    Instances trainData = WekaUtils.removeInstanceId(regressionTrainData, false);
    Instances testData = WekaUtils.removeInstanceId(regressionTestData, false);
    cl.buildClassifier(trainData);
    Evaluation eval = WekaUtils.getEvaluationSinglelabel(cl, trainData, testData);
    assertEquals(0.45, eval.correlationCoefficient(), 0.01);
}
Also used : Instances(weka.core.Instances) Evaluation(weka.classifiers.Evaluation) SMOreg(weka.classifiers.functions.SMOreg) Test(org.junit.Test)

Aggregations

Evaluation (weka.classifiers.Evaluation)4 Instances (weka.core.Instances)3 Test (org.junit.Test)2 File (java.io.File)1 ASEvaluation (weka.attributeSelection.ASEvaluation)1 Classifier (weka.classifiers.Classifier)1 NaiveBayes (weka.classifiers.bayes.NaiveBayes)1 SMO (weka.classifiers.functions.SMO)1 SMOreg (weka.classifiers.functions.SMOreg)1