@@ -32,6 +32,8 @@ public class ClassificationOfFloatValues {
32
32
private int [][] sortedProbability ;
33
33
private int numberOfClasses ;
34
34
35
+ private boolean [] validationModel = {false , false , false };
36
+
35
37
36
38
// Function to add the members of the class
37
39
public float [][] output () { return this .predictorData ; }
@@ -47,12 +49,12 @@ public ClassificationOfFloatValues(String dataset) throws Exception {
47
49
this .datasetName = dataset ;
48
50
}
49
51
50
- // --- Function for creating
52
+ // --- Function for processing the data (reading and writing the data to an array)
51
53
public void dataProcessing () throws Exception {
54
+ // Get row and column count
52
55
this .rowCount = CSVread .calcRowCount (this .datasetName , this .index );
53
56
this .columnCount = CSVread .calcColumnCount (this .datasetName , this .index );
54
- //System.out.println(this.rowCount);
55
- //System.out.println(this.columnCount);
57
+ // Get predictor and result data
56
58
this .predictorData = CSVread .transformPredictorData (this .datasetName , this .index , this .header , this .columnCount , this .rowCount );
57
59
this .resultData = CSVread .transformResultData (this .datasetName , this .index , this .header , this .columnCount , this .rowCount );
58
60
this .dataProcessingBool = true ;
@@ -77,56 +79,85 @@ public void dataSubdivision () {
77
79
78
80
79
81
// --- Functions for additional user control -----------------------------------------------------------------------
80
- // --- Function for changing the ratio between training and testing data
82
+ // --- Functions for setting the index and header data
81
83
public void setIndex (boolean index ) { this .index = index ; }
84
+
82
85
public void setHeader (boolean header ) { this .header = header ; }
86
+
87
+ // --- Function for changing the data density to clear extreme values | Not working
83
88
public void setDensity (float density ) {this .density = density ;}
89
+
90
+ // --- Function for changing the ratio between training and testing data
84
91
public void dataValidation (float trainingData ) {
85
92
this .validation [0 ] = trainingData ;
86
93
this .validation [1 ] = 1 - trainingData ;
87
94
}
95
+ // --- Function for setting the validation model
96
+ public void setEvaluation (String evaluationName ) {
97
+ if (evaluationName .equals ("Confusion Matrix" )) {
98
+ this .validationModel [0 ] = true ;
99
+ }else if (evaluationName .equals ("Simple Confusion Matrix" )) {
100
+ this .validationModel [1 ] = true ;
101
+ }else if (evaluationName .equals ("Normalized Confusion Matrix" )) {
102
+ this .validationModel [2 ] = true ;
103
+ }
104
+ }
88
105
89
106
90
107
// --- Functions for evaluating the machine learning results -------------------------------------------------------
108
+ // --- Function for printing confusion matrices
91
109
public void evaluateResults () {
110
+ // Creating an object to calculate confusion matrices
92
111
DATA_evaluation evaluationObject = new DATA_evaluation (this .testDataResults ,
93
112
this .columnCount - this .numberOfTrainingData ,
94
113
this .predictedTestData ,
95
114
this .sortedProbability ,
96
115
this .numberOfClasses );
97
- int [][] asdf = evaluationObject .getConfusionMatrixSimple ();
98
- evaluationObject .getConfusionMatrixNormalized ();
99
- }
100
- public void confusionMatrix () {
101
- if (this .MLAlgorithm == "DistanceClassification" ) {
102
- System .out .println ("nice confusion" );
116
+
117
+ // Printing a basic confusion matrix
118
+ if (this .validationModel [0 ] == true ) {
119
+ System .out .println ("\n Confusion Matrix" );
120
+ evaluationObject .getConfusionMatrix ();
121
+ }
122
+ // Printing a simplified confusion matrix
123
+ if (this .validationModel [1 ] == true ) {
124
+ System .out .println ("\n Simple Confusion Matrix" );
125
+ evaluationObject .getConfusionMatrixSimple ();
103
126
}
104
- else {
105
- System .out .println ("There is no algorithm" );
127
+ // Printing a normalized confusion matrix
128
+ if (this .validationModel [2 ] == true ) {
129
+ System .out .println ("\n Normalized Confusion Matrix" );
130
+ evaluationObject .getConfusionMatrixNormalized ();
106
131
}
132
+
107
133
}
108
134
109
135
110
136
// --- Functions for private calculations --------------------------------------------------------------------------
111
137
// --- Function for returning usable index data
112
138
private int returnIndex () {
113
139
// If there is an index it returns -1 because the usable data of the processed data has one element less
140
+ // The index does not belong to the important data
114
141
if (this .index == true ) { return -1 ; } else { return 0 ; }
115
142
}
116
143
117
- //
144
+ // --- Function for checking if all required processes have been completed successful before starting the
145
+ // classification algorithms
118
146
private boolean checkRequiredProcesses () {
147
+ // dataProcessingBool: Process the CSV data (reading)
148
+ // dataSubdivisionBool: Dividing the data into training and testing data
119
149
if (this .dataProcessingBool == true &&
120
150
this .dataSubdivisionBool == true ) {
121
151
return true ;
152
+ }else {
153
+ if (this .dataProcessingBool == false ) {
154
+ System .out .println ("Error 310 | The data has not been divided into training and testing data!" );
155
+ }
156
+ if (this .dataSubdivisionBool == false ) {
157
+ System .out .println ("Error 311 | The data has not been divided into training and testing data!" );
158
+ }
159
+ return false ;
122
160
}
123
- if (this .dataProcessingBool == false ) {
124
- System .out .println ("Error 310 | The data has not been divided into training and testing data!" );
125
- }
126
- if (this .dataSubdivisionBool == false ) {
127
- System .out .println ("Error 311 | The data has not been divided into training and testing data!" );
128
- }
129
- return false ;
130
161
}
131
162
132
163
@@ -149,9 +180,10 @@ public void distanceClassification (){
149
180
classificationObject .setTestData (this .testDataPredictors , this .testDataResults , this .rowCount , this .columnCount - this .numberOfTrainingData );
150
181
classificationObject .testModel ();
151
182
183
+ // Return the number of found classes
152
184
this .numberOfClasses = classificationObject .getNumberOfClasses ();
153
185
154
- // Get the test data
186
+ // Get the predicted text data
155
187
this .predictedTestData = classificationObject .getPredictedTestData ();
156
188
this .sortedProbability = classificationObject .getSortedProbability ();
157
189
}
0 commit comments