-
Notifications
You must be signed in to change notification settings - Fork 0
/
NaiveBayes.java
29 lines (24 loc) · 1.03 KB
/
NaiveBayes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.dm;
import java.io.BufferedReader;
import java.io.FileReader;
import weka.classifiers.evaluation.output.prediction.PlainText;
import weka.classifiers.Evaluation;
import weka.core.Instances;
public class NaiveBayes {
public static void main(String[] args) throws Exception {
BufferedReader readerTrain = new BufferedReader(new FileReader(args[0]));
BufferedReader readerTest = new BufferedReader(new FileReader(args[1]));
Instances train = new Instances(readerTrain);
Instances test = new Instances(readerTest);
train.setClassIndex(0);
test.setClassIndex(0);
weka.classifiers.bayes.NaiveBayes cls = new weka.classifiers.bayes.NaiveBayes();
cls.buildClassifier(train);
Evaluation eval = new Evaluation(train);
eval.evaluateModel(cls,test);
System.out.println(eval.toSummaryString("\nResults\n======\n", true));
System.out.println(eval.toClassDetailsString());
readerTrain.close();
readerTest.close();
}
}