@@ -11,6 +11,7 @@ public class DATA_evaluation {
11
11
12
12
private boolean createConfusionMatrix = false ;
13
13
14
+ // --- Creating a constructor for data evaluation
14
15
protected DATA_evaluation (String [] testDataResults , int columnCount , String [][][] predictedTestData , int [][] sortedProbability , int numberOfClasses ) {
15
16
this .testDataResults = testDataResults ;
16
17
this .columnCount = columnCount ;
@@ -23,20 +24,23 @@ protected DATA_evaluation(String[] testDataResults, int columnCount, String[][][
23
24
24
25
// --- Function for creating a basic confusion matrix for further calculations -------------------------------------
25
26
private void confusionMatrix () {
26
-
27
27
// Resetting the confusion matrix
28
28
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
29
29
for (int j = 0 ; j < this .numberOfClasses ; j ++) {
30
30
this .confustionMatrix [i ][j ] = 0 ;
31
31
}
32
32
}
33
33
34
+ // Going through every column of the data (only test data)
34
35
for (int i = 0 ; i < this .columnCount ; i ++) {
36
+ // Compare the predicted result with the actual result
35
37
if (this .testDataResults [i ].equals (this .predictedTestData [i ][this .sortedProbability [i ][0 ]][0 ])) {
38
+ // If true: The data has been predicted truly
36
39
this .confustionMatrix [this .sortedProbability [i ][0 ]][this .sortedProbability [i ][0 ]]++;
37
40
}
41
+ // If the predicted data does not match the actual result, it has been predicted falsely
38
42
else {
39
-
43
+ // Writing data as a false prediction to the confusion matrix
40
44
for (int j = 0 ; j < this .numberOfClasses ; j ++) {
41
45
if (this .testDataResults [i ].equals (this .predictedTestData [i ][this .sortedProbability [i ][j ]][0 ])) {
42
46
this .confustionMatrix [this .sortedProbability [i ][0 ]][this .sortedProbability [i ][j ]]++;
@@ -48,10 +52,12 @@ private void confusionMatrix() {
48
52
49
53
// --- Printing a basic confusion matrix
50
54
protected void getConfusionMatrix () {
55
+ // If the confusion matrix has not been created yet, it will be
51
56
if (!this .createConfusionMatrix ) {
52
57
confusionMatrix ();
53
58
}
54
59
60
+ // Printing every element of the confusion matrix
55
61
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
56
62
for (int j = 0 ; j < this .numberOfClasses ; j ++) {
57
63
System .out .print (confustionMatrix [i ][j ] + " " );
@@ -62,26 +68,32 @@ protected void getConfusionMatrix() {
62
68
63
69
// --- Printing a simple confusion matrix
64
70
protected void getConfusionMatrixSimple () {
71
+ // If the confusion matrix has not been created yet, it will be
65
72
if (!this .createConfusionMatrix ) {
66
73
confusionMatrix ();
67
74
}
68
75
76
+ // Creating an array for calculating a simple confusion matrix
69
77
int [][] confusionMatrixSimple = new int [this .numberOfClasses ][2 ];
70
78
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
71
79
for (int j = 0 ; j < 2 ; j ++) {
72
80
confusionMatrixSimple [i ][j ] = 0 ;
73
81
}
74
82
}
75
83
84
+ // Going through every column of the data (only test data)
76
85
for (int i = 0 ; i < this .columnCount ; i ++) {
86
+ // If the data has been predicted correctly it is TT
77
87
if (this .testDataResults [i ].equals (this .predictedTestData [i ][this .sortedProbability [i ][0 ]][0 ])) {
78
88
confusionMatrixSimple [this .sortedProbability [i ][0 ]][0 ]++;
79
89
}
90
+ // If the data has been predicted correctly it is TN
80
91
else {
81
92
confusionMatrixSimple [this .sortedProbability [i ][0 ]][1 ]++;
82
93
}
83
94
}
84
95
96
+ // Printing every element of the simple confusion matrix
85
97
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
86
98
for (int j = 0 ; j < 2 ; j ++) {
87
99
System .out .print (confusionMatrixSimple [i ][j ] + " " );
@@ -94,12 +106,17 @@ protected void getConfusionMatrixSimple() {
94
106
95
107
// --- Printing a normalized confusion matrix
96
108
protected void getConfusionMatrixNormalized () {
109
+ // If the confusion matrix has not been created yet, it will be
97
110
if (!this .createConfusionMatrix ) {
98
111
confusionMatrix ();
99
112
}
113
+
114
+ // Creating an array for calculating a normalized confusion matrix
100
115
float [][] confusionMatrixNormalized = new float [this .numberOfClasses ][this .numberOfClasses ];
101
116
117
+ // Going through every column of the data (only test data)
102
118
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
119
+ // Adding all predicted values per class
103
120
int tempCount = 0 ;
104
121
for (int j = 0 ; j < this .numberOfClasses ; j ++) {
105
122
tempCount += this .confustionMatrix [i ][j ];
@@ -108,12 +125,14 @@ protected void getConfusionMatrixNormalized() {
108
125
if (tempCount == 0 ) {
109
126
continue ;
110
127
}
128
+
129
+ // Dividing the predicted data per class
111
130
for (int j = 0 ; j < this .numberOfClasses ; j ++) {
112
131
confusionMatrixNormalized [i ][j ] = (float )this .confustionMatrix [i ][j ] / (float )tempCount ;
113
132
}
114
-
115
133
}
116
134
135
+ // Printing every element of the normalized confusion matrix
117
136
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
118
137
for (int j = 0 ; j < this .numberOfClasses ; j ++) {
119
138
System .out .print (confusionMatrixNormalized [i ][j ] + " " );
0 commit comments