@@ -25,73 +25,93 @@ public class DistanceClassification {
25
25
private int [][] sortedProbability ;
26
26
27
27
28
+ // --- Creating an object for distance classification --------------------------------------------------------------
28
29
protected DistanceClassification (float [][] trainingDataPredictors , String [] trainingDataResults , int rowCount , int columnCount , float density ) {
30
+ //Setting specific attributes
29
31
this .trainingDataPredictors = trainingDataPredictors ;
30
32
this .trainingDataResults = trainingDataResults ;
31
33
this .rowCount = rowCount ;
32
34
this .columnCount = columnCount ;
33
35
this .density = density ;
34
36
37
+ // Getting the different classification classes
35
38
getClassificationClasses ();
36
39
40
+ // Sorting the classification data
37
41
sortClassificationData ();
38
42
43
+ // Calculating the mean per feature (to calculate the distance)
39
44
calcFeatureMean ();
40
45
}
41
46
47
+ // --- Functions for returning classification data for internal use in other classes -------------------------------
48
+ // --- Function for returning the number of different classes
42
49
protected int getNumberOfClasses () {
43
50
return this .numberOfClasses ;
44
51
}
45
52
53
+ // --- Function for returning the sorted classification data (after classification)
46
54
protected float [][][] getSortedClassificationData () {
47
55
return this .sortedClassificationData ;
48
56
}
49
57
58
+ // --- Function for returning the predicted test data (probability per class)
50
59
protected String [][][] getPredictedTestData () {
51
60
return this .predictedTestData ;
52
61
}
53
62
63
+ // --- Function for returning the sorted probability (ranking of the highest probability)
54
64
protected int [][] getSortedProbability () {
55
65
return this .sortedProbability ;
56
66
}
57
67
68
+ // --- Function for returning the mean value per feature
58
69
protected float [][] getFeatureMean () {
59
70
return this .featureMean ;
60
71
}
61
72
73
+ // --- Required Functions for classifying the data -----------------------------------------------------------------
74
+ // All Functions have to been called in the ClassificationOfFloatValues.java file
75
+
76
+ // --- Function for setting the test data (with an upper and lower boundary -> already set in the classification file)
62
77
protected void setTestData (float [][] testDataPredictors , String [] testDataResults , int rowCount , int columnCount ) {
63
78
this .testDataPredictors = testDataPredictors ;
64
79
this .testDataResults = testDataResults ;
65
80
this .testDataRowCount = rowCount ;
66
81
this .testDataColumnCount = columnCount ;
67
82
}
68
83
84
+ // --- Calling a Function for testing the model
69
85
protected void testModel () {
70
86
testClassificationModel ();
71
87
}
72
88
89
+ // --- Private Functions for intern calculations of the actual classification --------------------------------------
90
+ // --- Function for getting the different classification classes and their number
73
91
private void getClassificationClasses () {
74
92
int numberOfClasses = 0 ;
75
93
List <String > classes = new ArrayList <String >();
76
94
List <String > tempClasses = Arrays .asList (this .trainingDataResults );
77
95
96
+ // Going through every column of the dataset (test data) and reading the result data (class)
78
97
for (int i = 0 ; i < this .columnCount ; i ++) {
98
+ // If the class is not already in the saved in the class array list, it will be added
79
99
if (!classes .contains (tempClasses .get (i ))) {
80
100
classes .add (tempClasses .get (i ));
81
101
numberOfClasses ++;
82
- //System.out.println(i);
83
102
}
84
103
}
85
104
86
105
this .numberOfClasses = numberOfClasses ;
87
106
this .classes = new String [this .numberOfClasses ];
88
107
108
+ // Converting the array list to an array
89
109
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
90
110
this .classes [i ] = classes .get (i );
91
- //System.out.println(this.classes[i]);
92
111
}
93
112
}
94
113
114
+ // --- Function for sorting the classified data
95
115
private void sortClassificationData () {
96
116
ArrayList <ArrayList <ArrayList <Float >>> tempSortedClassificationData = new ArrayList <>();
97
117
int [] tempNumberDataPerClass = new int [this .rowCount -1 ];
@@ -140,6 +160,7 @@ private void sortClassificationData() {
140
160
}
141
161
}
142
162
163
+ // --- Function for calculating the mean for every feature (training the model)
143
164
private void calcFeatureMean () {
144
165
this .featureMean = new float [this .numberOfClasses ][this .rowCount -1 ];
145
166
for (int i = 0 ; i < this .numberOfClasses ; i ++) {
@@ -154,6 +175,7 @@ private void calcFeatureMean() {
154
175
}
155
176
}
156
177
178
+ // --- Function for testing the classification model
157
179
private void testClassificationModel () {
158
180
this .predictedTestData = new String [this .testDataColumnCount ][this .numberOfClasses ][2 ];
159
181
this .sortedProbability = new int [this .testDataColumnCount ][this .numberOfClasses ];
0 commit comments