-
Notifications
You must be signed in to change notification settings - Fork 0
/
UntunedNBTree.java
66 lines (51 loc) · 2.18 KB
/
UntunedNBTree.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import weka.classifiers.trees.NBTree;
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
public class UntunedNBTree {
public static void main(String[] args) throws Exception{
// load data sets
Instances train = new Instances(
new BufferedReader(
new FileReader("/Weka-3-6/ProjectMilestone5/spambase_train.arff")));
Instances test = new Instances(
new BufferedReader(
new FileReader("/Weka-3-6/ProjectMilestone5/spambase_test.arff")));
train.setClassIndex(train.numAttributes() - 1);
test.setClassIndex(test.numAttributes()-1);
//Classifier [] ClassifierArray=new Classifier[3];
//ClassifierArray[1]=new J48();
//ClassifierArray[0]=new NaiveBayes();
//ClassifierArray[2]=new NBTree();
NBTree vs=new NBTree();
//String[] options=new String[3];
//options[2]="-R MAJ";
//options[1]="-B weka.classifiers.functions.SMO -B weka.classifiers.bayes.NaiveBayes";
//options[0]="-S <2>";
//vs.setOptions(options);
//vs.setClassifiers(ClassifierArray);
vs.buildClassifier(train);
//find optimal parameter
//ps.addCVParameter("F 1 5 10");
//ps.addCVParameter("S 1 10 10");
//Dagging cls = new Dagging();
//change the base classifier
//cls.setClassifier(new NBTree());
//change the parameter for dagging
//cls.setNumFolds(1);
//cls.setSeed(7);
//cls.buildClassifier(train);
//System.out.println(vs.getCombinationRule());
//System.out.println(vs.getOptions());
PrintWriter pw=new PrintWriter(new FileWriter("/Weka-3-6/ProjectMilestone5/spambase-LB.txt"));
//System.out.println(Utils.joinOptions(ps.getBestClassifierOptions()));
for (int i = 0; i < test.numInstances(); i++) {
double pred = vs.classifyInstance(test.instance(i));
pw.println(pred);
}
pw.close();
//weka.core.SerializationHelper.write("/Weka-3-6/ProjectMilestone3/ionosphere.model", vs);
}
}