-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExample8.java
executable file
·65 lines (49 loc) · 2.25 KB
/
Example8.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
package examples.ml_examples.example8;
import maths.ConfusionMatrix;
import java.util.ArrayList;
import java.util.List;
public class Example8 {
public static void main(String[] args){
final int SIZE = 165;
final int N_CLASSES = 2;
List<Integer> actual = new ArrayList<>();
for(int i=0; i< SIZE; ++i){
if(i < 60){
actual.add(0);
}
else{
actual.add(1);
}
}
List<Integer> predicted = new ArrayList<>();
for(int i=0; i< SIZE; ++i){
if(i < 50){
predicted.add(0);
}
else if(i>=50 && i<65){
predicted.add(1);
}
else if(i>=65 && i<70){
predicted.add(0);
}
else{
predicted.add(1);
}
}
/*ConfusionMatrix confusionMatrix = new ConfusionMatrix(actual, predicted, N_CLASSES);
// let's compute some metrics
System.out.println("TP: "+confusionMatrix.getClassCounts(1));
System.out.println("TN: "+confusionMatrix.getClassCounts(0));
System.out.println("FP: "+confusionMatrix.getClassCountsAsOtherClass(0,1));
System.out.println("FN: "+confusionMatrix.getClassCountsAsOtherClass(1,0));
System.out.println("Accuracy is: " + confusionMatrix.accuracy());
System.out.println("Misclassification Rate: " + confusionMatrix.misclassificationRate());
System.out.println("TP Rate or Recall: " + confusionMatrix.recallClass(1));
System.out.println("TN Rate or Specificity: " + confusionMatrix.recallClass(0));
System.out.println("False Positive Rate: " + (double)confusionMatrix.getClassCountsAsOtherClass(0,1)/60.0);
System.out.println("Precision: " + (double)confusionMatrix.getClassCounts(1)/
(double) (confusionMatrix.getClassCountsAsOtherClass(0,1) + confusionMatrix.getClassCounts(1)));
System.out.println("Prevalence: " + (double)(confusionMatrix.getClassCountsAsOtherClass(1,0) +
confusionMatrix.getClassCounts(1))/(double) confusionMatrix.totalCount());*/
}
}