@@ -32,6 +32,8 @@ public class ClassificationOfFloatValues {
3232 private int [][] sortedProbability ;
3333 private int numberOfClasses ;
3434
35+ private boolean [] validationModel = {false , false , false };
36+
3537
3638 // Function to add the members of the class
3739 public float [][] output () { return this .predictorData ; }
@@ -47,12 +49,12 @@ public ClassificationOfFloatValues(String dataset) throws Exception {
4749 this .datasetName = dataset ;
4850 }
4951
50- // --- Function for creating
52+ // --- Function for processing the data (reading and writing the data to an array)
5153 public void dataProcessing () throws Exception {
54+ // Get row and column count
5255 this .rowCount = CSVread .calcRowCount (this .datasetName , this .index );
5356 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
5658 this .predictorData = CSVread .transformPredictorData (this .datasetName , this .index , this .header , this .columnCount , this .rowCount );
5759 this .resultData = CSVread .transformResultData (this .datasetName , this .index , this .header , this .columnCount , this .rowCount );
5860 this .dataProcessingBool = true ;
@@ -77,58 +79,85 @@ public void dataSubdivision () {
7779
7880
7981 // --- 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
8183 public void setIndex (boolean index ) { this .index = index ; }
84+
8285 public void setHeader (boolean header ) { this .header = header ; }
86+
87+ // --- Function for changing the data density to clear extreme values | Not working
8388 public void setDensity (float density ) {this .density = density ;}
89+
90+ // --- Function for changing the ratio between training and testing data
8491 public void dataValidation (float trainingData ) {
8592 this .validation [0 ] = trainingData ;
8693 this .validation [1 ] = 1 - trainingData ;
8794 }
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+ }
88105
89106
90107 // --- Functions for evaluating the machine learning results -------------------------------------------------------
108+ // --- Function for printing confusion matrices
91109 public void evaluateResults () {
110+ // Creating an object to calculate confusion matrices
92111 DATA_evaluation evaluationObject = new DATA_evaluation (this .testDataResults ,
93112 this .columnCount - this .numberOfTrainingData ,
94113 this .predictedTestData ,
95114 this .sortedProbability ,
96115 this .numberOfClasses );
97- System .out .println ("\n Simple Confusion Matrix" );
98- evaluationObject .getConfusionMatrixSimple ();
99- System .out .println ("\n Normalized Confusion Matrix" );
100- evaluationObject .getConfusionMatrixNormalized ();
101- }
102- public void confusionMatrix () {
103- if (this .MLAlgorithm == "DistanceClassification" ) {
104- 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 ();
105126 }
106- else {
107- 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 ();
108131 }
132+
109133 }
110134
111135
112136 // --- Functions for private calculations --------------------------------------------------------------------------
113137 // --- Function for returning usable index data
114138 private int returnIndex () {
115139 // 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
116141 if (this .index == true ) { return -1 ; } else { return 0 ; }
117142 }
118143
119- //
144+ // --- Function for checking if all required processes have been completed successful before starting the
145+ // classification algorithms
120146 private boolean checkRequiredProcesses () {
147+ // dataProcessingBool: Process the CSV data (reading)
148+ // dataSubdivisionBool: Dividing the data into training and testing data
121149 if (this .dataProcessingBool == true &&
122150 this .dataSubdivisionBool == true ) {
123151 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 ;
124160 }
125- if (this .dataProcessingBool == false ) {
126- System .out .println ("Error 310 | The data has not been divided into training and testing data!" );
127- }
128- if (this .dataSubdivisionBool == false ) {
129- System .out .println ("Error 311 | The data has not been divided into training and testing data!" );
130- }
131- return false ;
132161 }
133162
134163
@@ -151,9 +180,10 @@ public void distanceClassification (){
151180 classificationObject .setTestData (this .testDataPredictors , this .testDataResults , this .rowCount , this .columnCount - this .numberOfTrainingData );
152181 classificationObject .testModel ();
153182
183+ // Return the number of found classes
154184 this .numberOfClasses = classificationObject .getNumberOfClasses ();
155185
156- // Get the test data
186+ // Get the predicted text data
157187 this .predictedTestData = classificationObject .getPredictedTestData ();
158188 this .sortedProbability = classificationObject .getSortedProbability ();
159189 }
0 commit comments