@@ -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,56 +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- 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 ();
103126 }
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 ();
106131 }
132+
107133 }
108134
109135
110136 // --- Functions for private calculations --------------------------------------------------------------------------
111137 // --- Function for returning usable index data
112138 private int returnIndex () {
113139 // 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
114141 if (this .index == true ) { return -1 ; } else { return 0 ; }
115142 }
116143
117- //
144+ // --- Function for checking if all required processes have been completed successful before starting the
145+ // classification algorithms
118146 private boolean checkRequiredProcesses () {
147+ // dataProcessingBool: Process the CSV data (reading)
148+ // dataSubdivisionBool: Dividing the data into training and testing data
119149 if (this .dataProcessingBool == true &&
120150 this .dataSubdivisionBool == true ) {
121151 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 ;
122160 }
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 ;
130161 }
131162
132163
@@ -149,9 +180,10 @@ public void distanceClassification (){
149180 classificationObject .setTestData (this .testDataPredictors , this .testDataResults , this .rowCount , this .columnCount - this .numberOfTrainingData );
150181 classificationObject .testModel ();
151182
183+ // Return the number of found classes
152184 this .numberOfClasses = classificationObject .getNumberOfClasses ();
153185
154- // Get the test data
186+ // Get the predicted text data
155187 this .predictedTestData = classificationObject .getPredictedTestData ();
156188 this .sortedProbability = classificationObject .getSortedProbability ();
157189 }
0 commit comments