Changeset 11683
- Timestamp:
- 12/14/14 23:20:12 (10 years ago)
- Location:
- branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r11643 r11683 229 229 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" /> 230 230 <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" /> 231 <Compile Include="OnlineCalculators\ClassificationPerformanceMeasuresCalculator.cs" /> 231 232 <Compile Include="OnlineCalculators\DependencyCalculator\HoeffdingsDependenceCalculator.cs" /> 232 233 <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRDependenceCalculator.cs" /> -
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r11622 r11683 35 35 private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)"; 36 36 37 private const string ClassificationPositiveClassValueResultName = "Classification positive class"; 37 38 private const string TrainingTruePositiveRateResultName = "True positive rate (training)"; 38 39 private const string TrainingTrueNegativeRateResultName = "True negative rate (training)"; … … 47 48 private const string TestFalsePositiveRateResultName = "False positive rate (test)"; 48 49 private const string TestFalseDiscoveryRateResultName = "False discovery rate (test)"; 49 private const string QualityMeasuresResultName = "Classification QualityMeasures";50 private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures"; 50 51 51 52 public new IClassificationModel Model { … … 77 78 } 78 79 79 #region Quality Measures 80 public ResultCollection QualityMeasures { 81 get { return ((ResultCollection)this[QualityMeasuresResultName].Value); } 82 protected set { (this[QualityMeasuresResultName].Value) = value; } 83 } 84 80 #region Classification performance measures 81 public ResultCollection ClassificationPerformanceMeasures { 82 get { return ((ResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); } 83 protected set { (this[ClassificationPerformanceMeasuresResultName].Value) = value; } 84 } 85 86 public string ClassificationPositiveClassValue { 87 get { return ((StringValue)ClassificationPerformanceMeasures[ClassificationPositiveClassValueResultName].Value).Value; } 88 protected set { ((StringValue)ClassificationPerformanceMeasures[ClassificationPositiveClassValueResultName].Value).Value = value; } 89 } 85 90 public double TrainingTruePositiveRate { 86 get { return ((DoubleValue) QualityMeasures[TrainingTruePositiveRateResultName].Value).Value; }87 protected set { ((DoubleValue) QualityMeasures[TrainingTruePositiveRateResultName].Value).Value = value; }88 } 89 public double TrainingTrueNegativeRate { 90 get { return ((DoubleValue) QualityMeasures[TrainingTrueNegativeRateResultName].Value).Value; }91 protected set { ((DoubleValue) QualityMeasures[TrainingTrueNegativeRateResultName].Value).Value = value; }91 get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingTruePositiveRateResultName].Value).Value; } 92 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingTruePositiveRateResultName].Value).Value = value; } 93 } 94 public double TrainingTrueNegativeRate { 95 get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingTrueNegativeRateResultName].Value).Value; } 96 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingTrueNegativeRateResultName].Value).Value = value; } 92 97 } 93 98 public double TrainingPositivePredictiveValue { 94 get { return ((DoubleValue) QualityMeasures[TrainingPositivePredictiveValueResultName].Value).Value; }95 protected set { ((DoubleValue) QualityMeasures[TrainingPositivePredictiveValueResultName].Value).Value = value; }99 get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingPositivePredictiveValueResultName].Value).Value; } 100 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingPositivePredictiveValueResultName].Value).Value = value; } 96 101 } 97 102 public double TrainingNegativePredictiveValue { 98 get { return ((DoubleValue) QualityMeasures[TrainingNegativePredictiveValueResultName].Value).Value; }99 protected set { ((DoubleValue) QualityMeasures[TrainingNegativePredictiveValueResultName].Value).Value = value; }103 get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingNegativePredictiveValueResultName].Value).Value; } 104 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingNegativePredictiveValueResultName].Value).Value = value; } 100 105 } 101 106 public double TrainingFalsePositiveRate { 102 get { return ((DoubleValue) QualityMeasures[TrainingFalsePositiveRateResultName].Value).Value; }103 protected set { ((DoubleValue) QualityMeasures[TrainingFalsePositiveRateResultName].Value).Value = value; }107 get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalsePositiveRateResultName].Value).Value; } 108 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalsePositiveRateResultName].Value).Value = value; } 104 109 } 105 110 public double TrainingFalseDiscoveryRate { 106 get { return ((DoubleValue)QualityMeasures[TrainingFalseDiscoveryRateResultName].Value).Value; } 107 protected set { ((DoubleValue)QualityMeasures[TrainingFalseDiscoveryRateResultName].Value).Value = value; } 108 } 109 111 get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalseDiscoveryRateResultName].Value).Value; } 112 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalseDiscoveryRateResultName].Value).Value = value; } 113 } 110 114 public double TestTruePositiveRate { 111 get { return ((DoubleValue) QualityMeasures[TestTruePositiveRateResultName].Value).Value; }112 protected set { ((DoubleValue) QualityMeasures[TestTruePositiveRateResultName].Value).Value = value; }115 get { return ((DoubleValue)ClassificationPerformanceMeasures[TestTruePositiveRateResultName].Value).Value; } 116 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestTruePositiveRateResultName].Value).Value = value; } 113 117 } 114 118 public double TestTrueNegativeRate { 115 get { return ((DoubleValue) QualityMeasures[TestTrueNegativeRateResultName].Value).Value; }116 protected set { ((DoubleValue) QualityMeasures[TestTrueNegativeRateResultName].Value).Value = value; }119 get { return ((DoubleValue)ClassificationPerformanceMeasures[TestTrueNegativeRateResultName].Value).Value; } 120 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestTrueNegativeRateResultName].Value).Value = value; } 117 121 } 118 122 public double TestPositivePredictiveValue { 119 get { return ((DoubleValue) QualityMeasures[TestPositivePredictiveValueResultName].Value).Value; }120 protected set { ((DoubleValue) QualityMeasures[TestPositivePredictiveValueResultName].Value).Value = value; }123 get { return ((DoubleValue)ClassificationPerformanceMeasures[TestPositivePredictiveValueResultName].Value).Value; } 124 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestPositivePredictiveValueResultName].Value).Value = value; } 121 125 } 122 126 public double TestNegativePredictiveValue { 123 get { return ((DoubleValue) QualityMeasures[TestNegativePredictiveValueResultName].Value).Value; }124 protected set { ((DoubleValue) QualityMeasures[TestNegativePredictiveValueResultName].Value).Value = value; }127 get { return ((DoubleValue)ClassificationPerformanceMeasures[TestNegativePredictiveValueResultName].Value).Value; } 128 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestNegativePredictiveValueResultName].Value).Value = value; } 125 129 } 126 130 public double TestFalsePositiveRate { 127 get { return ((DoubleValue) QualityMeasures[TestFalsePositiveRateResultName].Value).Value; }128 protected set { ((DoubleValue) QualityMeasures[TestFalsePositiveRateResultName].Value).Value = value; }131 get { return ((DoubleValue)ClassificationPerformanceMeasures[TestFalsePositiveRateResultName].Value).Value; } 132 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestFalsePositiveRateResultName].Value).Value = value; } 129 133 } 130 134 public double TestFalseDiscoveryRate { 131 get { return ((DoubleValue) QualityMeasures[TestFalseDiscoveryRateResultName].Value).Value; }132 protected set { ((DoubleValue) QualityMeasures[TestFalseDiscoveryRateResultName].Value).Value = value; }135 get { return ((DoubleValue)ClassificationPerformanceMeasures[TestFalseDiscoveryRateResultName].Value).Value; } 136 protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestFalseDiscoveryRateResultName].Value).Value = value; } 133 137 } 134 138 #endregion … … 146 150 Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue())); 147 151 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 148 Add QualityMeasuresResultCollection();152 AddClassificationPerformanceMeasuresResultCollection(); 149 153 } 150 154 … … 155 159 if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName)) 156 160 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 157 if (!this.ContainsKey(QualityMeasuresResultName)) 158 AddQualityMeasuresResultCollection(); 159 } 160 161 protected void AddQualityMeasuresResultCollection() { 162 ResultCollection qualityMeasuresResult = new ResultCollection(); 163 qualityMeasuresResult.Add(new Result(TrainingTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the training partition\n(TP/(TP+FN)).", new PercentValue())); 164 qualityMeasuresResult.Add(new Result(TrainingTrueNegativeRateResultName, "Specificity/True negative rate of the model on the training partition\n(TN/(FP+TN)).", new PercentValue())); 165 qualityMeasuresResult.Add(new Result(TrainingPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the training partition\n(TP/(TP+FP)).", new PercentValue())); 166 qualityMeasuresResult.Add(new Result(TrainingNegativePredictiveValueResultName, "Negative predictive value of the model on the training partition\n(TN/(TN+FN)).", new PercentValue())); 167 qualityMeasuresResult.Add(new Result(TrainingFalsePositiveRateResultName, "The false positive rate is the complement of the true negative rate of the model on the training partition.", new PercentValue())); 168 qualityMeasuresResult.Add(new Result(TrainingFalseDiscoveryRateResultName, "The false discovery rate is the complement of the positive predictive value of the model on the training partition.", new PercentValue())); 169 qualityMeasuresResult.Add(new Result(TestTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the test partition\n(TP/(TP+FN)).", new PercentValue())); 170 qualityMeasuresResult.Add(new Result(TestTrueNegativeRateResultName, "Specificity/True negative rate of the model on the test partition\n(TN/(FP+TN)).", new PercentValue())); 171 qualityMeasuresResult.Add(new Result(TestPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the test partition\n(TP/(TP+FP)).", new PercentValue())); 172 qualityMeasuresResult.Add(new Result(TestNegativePredictiveValueResultName, "Negative predictive value of the model on the test partition\n(TN/(TN+FN)).", new PercentValue())); 173 qualityMeasuresResult.Add(new Result(TestFalsePositiveRateResultName, "The false positive rate is the complement of the true negative rate of the model on the test partition.", new PercentValue())); 174 qualityMeasuresResult.Add(new Result(TestFalseDiscoveryRateResultName, "The false discovery rate is the complement of the positive predictive value of the model on the test partition.", new PercentValue())); 175 Add(new Result(QualityMeasuresResultName, "Classification quality measures.\nIn Multiclass Classification all misclassifications of the negative class will be treated as true negatives.", qualityMeasuresResult)); 161 if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) { 162 AddClassificationPerformanceMeasuresResultCollection(); 163 RecalculateResults(); 164 } 165 } 166 167 protected void AddClassificationPerformanceMeasuresResultCollection() { 168 ResultCollection performanceMeasures = new ResultCollection(); 169 performanceMeasures.Add(new Result(ClassificationPositiveClassValueResultName, "The positive class which is used for the performance measure calculations.", new StringValue())); 170 performanceMeasures.Add(new Result(TrainingTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the training partition\n(TP/(TP+FN)).", new PercentValue())); 171 performanceMeasures.Add(new Result(TrainingTrueNegativeRateResultName, "Specificity/True negative rate of the model on the training partition\n(TN/(FP+TN)).", new PercentValue())); 172 performanceMeasures.Add(new Result(TrainingPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the training partition\n(TP/(TP+FP)).", new PercentValue())); 173 performanceMeasures.Add(new Result(TrainingNegativePredictiveValueResultName, "Negative predictive value of the model on the training partition\n(TN/(TN+FN)).", new PercentValue())); 174 performanceMeasures.Add(new Result(TrainingFalsePositiveRateResultName, "The false positive rate is the complement of the true negative rate of the model on the training partition.", new PercentValue())); 175 performanceMeasures.Add(new Result(TrainingFalseDiscoveryRateResultName, "The false discovery rate is the complement of the positive predictive value of the model on the training partition.", new PercentValue())); 176 performanceMeasures.Add(new Result(TestTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the test partition\n(TP/(TP+FN)).", new PercentValue())); 177 performanceMeasures.Add(new Result(TestTrueNegativeRateResultName, "Specificity/True negative rate of the model on the test partition\n(TN/(FP+TN)).", new PercentValue())); 178 performanceMeasures.Add(new Result(TestPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the test partition\n(TP/(TP+FP)).", new PercentValue())); 179 performanceMeasures.Add(new Result(TestNegativePredictiveValueResultName, "Negative predictive value of the model on the test partition\n(TN/(TN+FN)).", new PercentValue())); 180 performanceMeasures.Add(new Result(TestFalsePositiveRateResultName, "The false positive rate is the complement of the true negative rate of the model on the test partition.", new PercentValue())); 181 performanceMeasures.Add(new Result(TestFalseDiscoveryRateResultName, "The false discovery rate is the complement of the positive predictive value of the model on the test partition.", new PercentValue())); 182 Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n 183 In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", performanceMeasures)); 176 184 } 177 185 … … 185 193 var positiveClassName = ProblemData.PositiveClassName; 186 194 double positiveClassValue = ProblemData.GetClassValue(positiveClassName); 187 QualityCalculator trainingQualityCalculator = new QualityCalculator(positiveClassValue); 188 QualityCalculator testQualityCalculator = new QualityCalculator(positiveClassValue); 195 ClassificationPositiveClassValue = positiveClassName; 196 ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassValue); 197 ClassificationPerformanceMeasuresCalculator testPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassValue); 189 198 190 199 OnlineCalculatorError errorState; … … 205 214 TestNormalizedGiniCoefficient = testNormalizedGini; 206 215 207 // qualitymeasures training partition208 training QualityCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState);216 //performance measures training partition 217 trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState); 209 218 if (errorState != OnlineCalculatorError.None) { 210 219 TrainingTruePositiveRate = double.NaN; … … 215 224 TrainingFalseDiscoveryRate = double.NaN; 216 225 } else { 217 TrainingTruePositiveRate = training QualityCalculator.TruePositiveRate;218 TrainingTrueNegativeRate = training QualityCalculator.TrueNegativeRate;219 TrainingPositivePredictiveValue = training QualityCalculator.PositivePredictiveValue;220 TrainingNegativePredictiveValue = training QualityCalculator.NegativePredictiveValue;221 TrainingFalsePositiveRate = training QualityCalculator.FalsePositiveRate;222 TrainingFalseDiscoveryRate = training QualityCalculator.FalseDiscoveryRate;226 TrainingTruePositiveRate = trainingPerformanceCalculator.TruePositiveRate; 227 TrainingTrueNegativeRate = trainingPerformanceCalculator.TrueNegativeRate; 228 TrainingPositivePredictiveValue = trainingPerformanceCalculator.PositivePredictiveValue; 229 TrainingNegativePredictiveValue = trainingPerformanceCalculator.NegativePredictiveValue; 230 TrainingFalsePositiveRate = trainingPerformanceCalculator.FalsePositiveRate; 231 TrainingFalseDiscoveryRate = trainingPerformanceCalculator.FalseDiscoveryRate; 223 232 } 224 // qualitymeasures test partition225 test QualityCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState);233 //performance measures test partition 234 testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState); 226 235 if (errorState != OnlineCalculatorError.None) { 227 236 TestTruePositiveRate = double.NaN; … … 232 241 TestFalseDiscoveryRate = double.NaN; 233 242 } else { 234 TestTruePositiveRate = test QualityCalculator.TruePositiveRate;235 TestTrueNegativeRate = test QualityCalculator.TrueNegativeRate;236 TestPositivePredictiveValue = test QualityCalculator.PositivePredictiveValue;237 TestNegativePredictiveValue = test QualityCalculator.NegativePredictiveValue;238 TestFalsePositiveRate = test QualityCalculator.FalsePositiveRate;239 TestFalseDiscoveryRate = test QualityCalculator.FalseDiscoveryRate;243 TestTruePositiveRate = testPerformanceCalculator.TruePositiveRate; 244 TestTrueNegativeRate = testPerformanceCalculator.TrueNegativeRate; 245 TestPositivePredictiveValue = testPerformanceCalculator.PositivePredictiveValue; 246 TestNegativePredictiveValue = testPerformanceCalculator.NegativePredictiveValue; 247 TestFalsePositiveRate = testPerformanceCalculator.FalsePositiveRate; 248 TestFalseDiscoveryRate = testPerformanceCalculator.FalseDiscoveryRate; 240 249 } 241 250 }
Note: See TracChangeset
for help on using the changeset viewer.