-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProgPerceptron.java
51 lines (40 loc) · 1.84 KB
/
ProgPerceptron.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
public class ProgPerceptron {
/**
* @param args
*/
public static void main(String[] args) {
/*String trainingHamDir = "D:\\Courses\\ML\\HW3\\train\\ham";
String trainingSpamDir = "D:\\Courses\\ML\\HW3\\train\\spam";
String testingHamDir = "D:\\Courses\\ML\\HW3\\test\\ham";
String testingSpamDir ="D:\\Courses\\ML\\HW3\\test\\spam";
String stopWord = "D:\\Courses\\ML\\HW3\\stopWords.txt";*/
double accuracy,accuracySW;
if(args.length != 7) {
System.out.println("Invalid Arguments: Please refer the README.txt for instructions");
return;
}
String trainingHamDir = args[0];
String trainingSpamDir = args[1];
String testingHamDir = args[2];
String testingSpamDir = args[3];
String stopWord = args[4];
PerceptronModel.eta = Double.parseDouble(args[5]);
PerceptronModel.iterations = Integer.parseInt(args[6]);
try {
System.out.println("===Training Perceptron model started without using stopWords===");
PerceptronModel perceptron = new PerceptronModel(trainingHamDir, trainingSpamDir);
perceptron.trainPerceptron();
System.out.println("Training successful!");
accuracy = perceptron.calculateAccuracy(testingHamDir,testingSpamDir);
System.out.println("Overall accuracy of Perceptron without using stopwords = " + accuracy + "%\n\n");
System.out.println("===Training Perceptron model started using stopWords===");
PerceptronModel perceptronWithoutSW = new PerceptronModel(trainingHamDir, trainingSpamDir,stopWord);
perceptronWithoutSW.trainPerceptron();
System.out.println("Trained successful!");
accuracySW = perceptronWithoutSW.calculateAccuracy(testingHamDir,testingSpamDir);
System.out.println("Overall Accuracy of Perceptron using stopwords = " + accuracySW + "%");
} catch (Exception e) {
e.printStackTrace();
}
}
}