Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47ef433

Browse files
author
Maximilian Wenk
committed
documentation and clean-up of DATA_evaluation.java
1 parent 02de9c1 commit 47ef433

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

‎src/classification/DATA_evaluation.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class DATA_evaluation {
1111

1212
private boolean createConfusionMatrix = false;
1313

14+
// --- Creating a constructor for data evaluation
1415
protected DATA_evaluation(String[] testDataResults, int columnCount, String[][][] predictedTestData, int[][] sortedProbability, int numberOfClasses) {
1516
this.testDataResults = testDataResults;
1617
this.columnCount = columnCount;
@@ -23,20 +24,23 @@ protected DATA_evaluation(String[] testDataResults, int columnCount, String[][][
2324

2425
// --- Function for creating a basic confusion matrix for further calculations -------------------------------------
2526
private void confusionMatrix() {
26-
2727
// Resetting the confusion matrix
2828
for (int i = 0; i < this.numberOfClasses; i++) {
2929
for (int j = 0; j < this.numberOfClasses; j++) {
3030
this.confustionMatrix[i][j] = 0;
3131
}
3232
}
3333

34+
// Going through every column of the data (only test data)
3435
for (int i = 0; i < this.columnCount; i++) {
36+
// Compare the predicted result with the actual result
3537
if (this.testDataResults[i].equals(this.predictedTestData[i][this.sortedProbability[i][0]][0])) {
38+
// If true: The data has been predicted truly
3639
this.confustionMatrix[this.sortedProbability[i][0]][this.sortedProbability[i][0]]++;
3740
}
41+
// If the predicted data does not match the actual result, it has been predicted falsely
3842
else {
39-
43+
// Writing data as a false prediction to the confusion matrix
4044
for (int j = 0; j < this.numberOfClasses; j++) {
4145
if (this.testDataResults[i].equals(this.predictedTestData[i][this.sortedProbability[i][j]][0])) {
4246
this.confustionMatrix[this.sortedProbability[i][0]][this.sortedProbability[i][j]]++;
@@ -48,10 +52,12 @@ private void confusionMatrix() {
4852

4953
// --- Printing a basic confusion matrix
5054
protected void getConfusionMatrix() {
55+
// If the confusion matrix has not been created yet, it will be
5156
if (!this.createConfusionMatrix) {
5257
confusionMatrix();
5358
}
5459

60+
// Printing every element of the confusion matrix
5561
for (int i = 0; i < this.numberOfClasses; i++) {
5662
for (int j = 0; j < this.numberOfClasses; j++) {
5763
System.out.print(confustionMatrix[i][j] + " ");
@@ -62,26 +68,32 @@ protected void getConfusionMatrix() {
6268

6369
// --- Printing a simple confusion matrix
6470
protected void getConfusionMatrixSimple() {
71+
// If the confusion matrix has not been created yet, it will be
6572
if (!this.createConfusionMatrix) {
6673
confusionMatrix();
6774
}
6875

76+
// Creating an array for calculating a simple confusion matrix
6977
int[][] confusionMatrixSimple = new int[this.numberOfClasses][2];
7078
for (int i = 0; i < this.numberOfClasses; i++) {
7179
for (int j = 0; j < 2; j++) {
7280
confusionMatrixSimple[i][j] = 0;
7381
}
7482
}
7583

84+
// Going through every column of the data (only test data)
7685
for (int i = 0; i < this.columnCount; i++) {
86+
// If the data has been predicted correctly it is TT
7787
if (this.testDataResults[i].equals(this.predictedTestData[i][this.sortedProbability[i][0]][0])) {
7888
confusionMatrixSimple[this.sortedProbability[i][0]][0]++;
7989
}
90+
// If the data has been predicted correctly it is TN
8091
else {
8192
confusionMatrixSimple[this.sortedProbability[i][0]][1]++;
8293
}
8394
}
8495

96+
// Printing every element of the simple confusion matrix
8597
for (int i = 0; i < this.numberOfClasses; i++) {
8698
for (int j = 0; j < 2; j++) {
8799
System.out.print(confusionMatrixSimple[i][j] + " ");
@@ -94,12 +106,17 @@ protected void getConfusionMatrixSimple() {
94106

95107
// --- Printing a normalized confusion matrix
96108
protected void getConfusionMatrixNormalized() {
109+
// If the confusion matrix has not been created yet, it will be
97110
if (!this.createConfusionMatrix) {
98111
confusionMatrix();
99112
}
113+
114+
// Creating an array for calculating a normalized confusion matrix
100115
float[][] confusionMatrixNormalized = new float[this.numberOfClasses][this.numberOfClasses];
101116

117+
// Going through every column of the data (only test data)
102118
for (int i = 0; i < this.numberOfClasses; i++) {
119+
// Adding all predicted values per class
103120
int tempCount = 0;
104121
for (int j = 0; j < this.numberOfClasses; j++) {
105122
tempCount += this.confustionMatrix[i][j];
@@ -108,12 +125,14 @@ protected void getConfusionMatrixNormalized() {
108125
if (tempCount == 0) {
109126
continue;
110127
}
128+
129+
// Dividing the predicted data per class
111130
for (int j = 0; j < this.numberOfClasses; j++) {
112131
confusionMatrixNormalized[i][j] = (float)this.confustionMatrix[i][j] / (float)tempCount;
113132
}
114-
115133
}
116134

135+
// Printing every element of the normalized confusion matrix
117136
for (int i = 0; i < this.numberOfClasses; i++) {
118137
for (int j = 0; j < this.numberOfClasses; j++) {
119138
System.out.print(confusionMatrixNormalized[i][j] + " ");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /