1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HEAL.Fossil;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
29 | [StorableType("6F44E140-22CF-48D3-B100-B6013F2B6608")]
|
---|
30 | public class ClassificationPerformanceMeasuresResultCollection : ResultCollection {
|
---|
31 | #region result names
|
---|
32 | protected const string ClassificationPositiveClassNameResultName = "Classification positive class";
|
---|
33 | protected const string TrainingTruePositiveRateResultName = "True positive rate (training)";
|
---|
34 | protected const string TrainingTrueNegativeRateResultName = "True negative rate (training)";
|
---|
35 | protected const string TrainingPositivePredictiveValueResultName = "Positive predictive value (training)";
|
---|
36 | protected const string TrainingNegativePredictiveValueResultName = "Negative predictive value (training)";
|
---|
37 | protected const string TrainingFalsePositiveRateResultName = "False positive rate (training)";
|
---|
38 | protected const string TrainingFalseDiscoveryRateResultName = "False discovery rate (training)";
|
---|
39 | protected const string TrainingF1ScoreResultName = "F1 score (training)";
|
---|
40 | protected const string TrainingMatthewsCorrelationResultName = "Matthews Correlation (training)";
|
---|
41 | protected const string TestTruePositiveRateResultName = "True positive rate (test)";
|
---|
42 | protected const string TestTrueNegativeRateResultName = "True negative rate (test)";
|
---|
43 | protected const string TestPositivePredictiveValueResultName = "Positive predictive value (test)";
|
---|
44 | protected const string TestNegativePredictiveValueResultName = "Negative predictive value (test)";
|
---|
45 | protected const string TestFalsePositiveRateResultName = "False positive rate (test)";
|
---|
46 | protected const string TestFalseDiscoveryRateResultName = "False discovery rate (test)";
|
---|
47 | protected const string TestF1ScoreResultName = "F1 score (test)";
|
---|
48 | protected const string TestMatthewsCorrelationResultName = "Matthews Correlation (test)";
|
---|
49 | #endregion
|
---|
50 |
|
---|
51 | public ClassificationPerformanceMeasuresResultCollection()
|
---|
52 | : base() {
|
---|
53 | AddMeasures();
|
---|
54 | }
|
---|
55 | [StorableConstructor]
|
---|
56 | protected ClassificationPerformanceMeasuresResultCollection(StorableConstructorFlag _) : base(_) {
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected ClassificationPerformanceMeasuresResultCollection(ClassificationPerformanceMeasuresResultCollection original, Cloner cloner)
|
---|
60 | : base(original, cloner) { }
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
62 | return new ClassificationPerformanceMeasuresResultCollection(this, cloner);
|
---|
63 | }
|
---|
64 |
|
---|
65 | #region result properties
|
---|
66 | public string ClassificationPositiveClassName {
|
---|
67 | get { return ((StringValue)this[ClassificationPositiveClassNameResultName].Value).Value; }
|
---|
68 | set { ((StringValue)this[ClassificationPositiveClassNameResultName].Value).Value = value; }
|
---|
69 | }
|
---|
70 | public double TrainingTruePositiveRate {
|
---|
71 | get { return ((DoubleValue)this[TrainingTruePositiveRateResultName].Value).Value; }
|
---|
72 | set { ((DoubleValue)this[TrainingTruePositiveRateResultName].Value).Value = value; }
|
---|
73 | }
|
---|
74 | public double TrainingTrueNegativeRate {
|
---|
75 | get { return ((DoubleValue)this[TrainingTrueNegativeRateResultName].Value).Value; }
|
---|
76 | set { ((DoubleValue)this[TrainingTrueNegativeRateResultName].Value).Value = value; }
|
---|
77 | }
|
---|
78 | public double TrainingPositivePredictiveValue {
|
---|
79 | get { return ((DoubleValue)this[TrainingPositivePredictiveValueResultName].Value).Value; }
|
---|
80 | set { ((DoubleValue)this[TrainingPositivePredictiveValueResultName].Value).Value = value; }
|
---|
81 | }
|
---|
82 | public double TrainingNegativePredictiveValue {
|
---|
83 | get { return ((DoubleValue)this[TrainingNegativePredictiveValueResultName].Value).Value; }
|
---|
84 | set { ((DoubleValue)this[TrainingNegativePredictiveValueResultName].Value).Value = value; }
|
---|
85 | }
|
---|
86 | public double TrainingFalsePositiveRate {
|
---|
87 | get { return ((DoubleValue)this[TrainingFalsePositiveRateResultName].Value).Value; }
|
---|
88 | set { ((DoubleValue)this[TrainingFalsePositiveRateResultName].Value).Value = value; }
|
---|
89 | }
|
---|
90 | public double TrainingFalseDiscoveryRate {
|
---|
91 | get { return ((DoubleValue)this[TrainingFalseDiscoveryRateResultName].Value).Value; }
|
---|
92 | set { ((DoubleValue)this[TrainingFalseDiscoveryRateResultName].Value).Value = value; }
|
---|
93 | }
|
---|
94 | public double TrainingF1Score {
|
---|
95 | get { return ((DoubleValue)this[TrainingF1ScoreResultName].Value).Value; }
|
---|
96 | set { ((DoubleValue)this[TrainingF1ScoreResultName].Value).Value = value; }
|
---|
97 | }
|
---|
98 | public double TrainingMatthewsCorrelation {
|
---|
99 | get { return ((DoubleValue)this[TrainingMatthewsCorrelationResultName].Value).Value; }
|
---|
100 | set { ((DoubleValue)this[TrainingMatthewsCorrelationResultName].Value).Value = value; }
|
---|
101 | }
|
---|
102 | public double TestTruePositiveRate {
|
---|
103 | get { return ((DoubleValue)this[TestTruePositiveRateResultName].Value).Value; }
|
---|
104 | set { ((DoubleValue)this[TestTruePositiveRateResultName].Value).Value = value; }
|
---|
105 | }
|
---|
106 | public double TestTrueNegativeRate {
|
---|
107 | get { return ((DoubleValue)this[TestTrueNegativeRateResultName].Value).Value; }
|
---|
108 | set { ((DoubleValue)this[TestTrueNegativeRateResultName].Value).Value = value; }
|
---|
109 | }
|
---|
110 | public double TestPositivePredictiveValue {
|
---|
111 | get { return ((DoubleValue)this[TestPositivePredictiveValueResultName].Value).Value; }
|
---|
112 | set { ((DoubleValue)this[TestPositivePredictiveValueResultName].Value).Value = value; }
|
---|
113 | }
|
---|
114 | public double TestNegativePredictiveValue {
|
---|
115 | get { return ((DoubleValue)this[TestNegativePredictiveValueResultName].Value).Value; }
|
---|
116 | set { ((DoubleValue)this[TestNegativePredictiveValueResultName].Value).Value = value; }
|
---|
117 | }
|
---|
118 | public double TestFalsePositiveRate {
|
---|
119 | get { return ((DoubleValue)this[TestFalsePositiveRateResultName].Value).Value; }
|
---|
120 | set { ((DoubleValue)this[TestFalsePositiveRateResultName].Value).Value = value; }
|
---|
121 | }
|
---|
122 | public double TestFalseDiscoveryRate {
|
---|
123 | get { return ((DoubleValue)this[TestFalseDiscoveryRateResultName].Value).Value; }
|
---|
124 | set { ((DoubleValue)this[TestFalseDiscoveryRateResultName].Value).Value = value; }
|
---|
125 | }
|
---|
126 | public double TestF1Score {
|
---|
127 | get { return ((DoubleValue)this[TestF1ScoreResultName].Value).Value; }
|
---|
128 | set { ((DoubleValue)this[TestF1ScoreResultName].Value).Value = value; }
|
---|
129 | }
|
---|
130 | public double TestMatthewsCorrelation {
|
---|
131 | get { return ((DoubleValue)this[TestMatthewsCorrelationResultName].Value).Value; }
|
---|
132 | set { ((DoubleValue)this[TestMatthewsCorrelationResultName].Value).Value = value; }
|
---|
133 | }
|
---|
134 | #endregion
|
---|
135 |
|
---|
136 | protected void AddMeasures() {
|
---|
137 | Add(new Result(ClassificationPositiveClassNameResultName, "The positive class which is used for the performance measure calculations.", new StringValue()));
|
---|
138 | Add(new Result(TrainingTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the training partition\n(TP/(TP+FN)).", new PercentValue()));
|
---|
139 | Add(new Result(TrainingTrueNegativeRateResultName, "Specificity/True negative rate of the model on the training partition\n(TN/(FP+TN)).", new PercentValue()));
|
---|
140 | Add(new Result(TrainingPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the training partition\n(TP/(TP+FP)).", new PercentValue()));
|
---|
141 | Add(new Result(TrainingNegativePredictiveValueResultName, "Negative predictive value of the model on the training partition\n(TN/(TN+FN)).", new PercentValue()));
|
---|
142 | 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()));
|
---|
143 | 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()));
|
---|
144 | Add(new Result(TrainingF1ScoreResultName, "The F1 score of the model on the training partition.", new DoubleValue()));
|
---|
145 | Add(new Result(TrainingMatthewsCorrelationResultName, "The Matthews correlation value of the model on the training partition.", new DoubleValue()));
|
---|
146 | Add(new Result(TestTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the test partition\n(TP/(TP+FN)).", new PercentValue()));
|
---|
147 | Add(new Result(TestTrueNegativeRateResultName, "Specificity/True negative rate of the model on the test partition\n(TN/(FP+TN)).", new PercentValue()));
|
---|
148 | Add(new Result(TestPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the test partition\n(TP/(TP+FP)).", new PercentValue()));
|
---|
149 | Add(new Result(TestNegativePredictiveValueResultName, "Negative predictive value of the model on the test partition\n(TN/(TN+FN)).", new PercentValue()));
|
---|
150 | 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()));
|
---|
151 | 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()));
|
---|
152 | Add(new Result(TestF1ScoreResultName, "The F1 score of the model on the test partition.", new DoubleValue()));
|
---|
153 | Add(new Result(TestMatthewsCorrelationResultName, "The Matthews correlation value of the model on the test partition.", new DoubleValue()));
|
---|
154 |
|
---|
155 | Reset();
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | public void Reset() {
|
---|
160 | TrainingTruePositiveRate = double.NaN;
|
---|
161 | TrainingTrueNegativeRate = double.NaN;
|
---|
162 | TrainingPositivePredictiveValue = double.NaN;
|
---|
163 | TrainingNegativePredictiveValue = double.NaN;
|
---|
164 | TrainingFalsePositiveRate = double.NaN;
|
---|
165 | TrainingFalseDiscoveryRate = double.NaN;
|
---|
166 | TrainingF1Score = double.NaN;
|
---|
167 | TrainingMatthewsCorrelation = double.NaN;
|
---|
168 | TestTruePositiveRate = double.NaN;
|
---|
169 | TestTrueNegativeRate = double.NaN;
|
---|
170 | TestPositivePredictiveValue = double.NaN;
|
---|
171 | TestNegativePredictiveValue = double.NaN;
|
---|
172 | TestFalsePositiveRate = double.NaN;
|
---|
173 | TestFalseDiscoveryRate = double.NaN;
|
---|
174 | TestF1Score = double.NaN;
|
---|
175 | TestMatthewsCorrelation = double.NaN;
|
---|
176 | }
|
---|
177 |
|
---|
178 | public void SetTrainingResults(ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator) {
|
---|
179 | if (!string.IsNullOrWhiteSpace(ClassificationPositiveClassName)
|
---|
180 | && !ClassificationPositiveClassName.Equals(trainingPerformanceCalculator.PositiveClassName))
|
---|
181 | throw new ArgumentException("Classification positive class of the training data doesn't match with the data of test partition.");
|
---|
182 | ClassificationPositiveClassName = trainingPerformanceCalculator.PositiveClassName;
|
---|
183 | TrainingTruePositiveRate = trainingPerformanceCalculator.TruePositiveRate;
|
---|
184 | TrainingTrueNegativeRate = trainingPerformanceCalculator.TrueNegativeRate;
|
---|
185 | TrainingPositivePredictiveValue = trainingPerformanceCalculator.PositivePredictiveValue;
|
---|
186 | TrainingNegativePredictiveValue = trainingPerformanceCalculator.NegativePredictiveValue;
|
---|
187 | TrainingFalsePositiveRate = trainingPerformanceCalculator.FalsePositiveRate;
|
---|
188 | TrainingFalseDiscoveryRate = trainingPerformanceCalculator.FalseDiscoveryRate;
|
---|
189 | }
|
---|
190 |
|
---|
191 | public void SetTestResults(ClassificationPerformanceMeasuresCalculator testPerformanceCalculator) {
|
---|
192 | if (!string.IsNullOrWhiteSpace(ClassificationPositiveClassName)
|
---|
193 | && !ClassificationPositiveClassName.Equals(testPerformanceCalculator.PositiveClassName))
|
---|
194 | throw new ArgumentException("Classification positive class of the test data doesn't match with the data of training partition.");
|
---|
195 | ClassificationPositiveClassName = testPerformanceCalculator.PositiveClassName;
|
---|
196 | TestTruePositiveRate = testPerformanceCalculator.TruePositiveRate;
|
---|
197 | TestTrueNegativeRate = testPerformanceCalculator.TrueNegativeRate;
|
---|
198 | TestPositivePredictiveValue = testPerformanceCalculator.PositivePredictiveValue;
|
---|
199 | TestNegativePredictiveValue = testPerformanceCalculator.NegativePredictiveValue;
|
---|
200 | TestFalsePositiveRate = testPerformanceCalculator.FalsePositiveRate;
|
---|
201 | TestFalseDiscoveryRate = testPerformanceCalculator.FalseDiscoveryRate;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | }
|
---|