source: stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationPerformanceMeasures.cs @ 11872

Last change on this file since 11872 was 11872, checked in by mkommend, 4 years ago

#2278: Merged r11762, r11763, r11764 and r11766 into stable.

File size: 11.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.DataAnalysis {
29  [StorableClass]
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 TestTruePositiveRateResultName = "True positive rate (test)";
40    protected const string TestTrueNegativeRateResultName = "True negative rate (test)";
41    protected const string TestPositivePredictiveValueResultName = "Positive predictive value (test)";
42    protected const string TestNegativePredictiveValueResultName = "Negative predictive value (test)";
43    protected const string TestFalsePositiveRateResultName = "False positive rate (test)";
44    protected const string TestFalseDiscoveryRateResultName = "False discovery rate (test)";
45    #endregion
46
47    public ClassificationPerformanceMeasuresResultCollection()
48      : base() {
49      AddMeasures();
50    }
51    [StorableConstructor]
52    protected ClassificationPerformanceMeasuresResultCollection(bool deserializing)
53      : base(deserializing) {
54    }
55
56    protected ClassificationPerformanceMeasuresResultCollection(ClassificationPerformanceMeasuresResultCollection original, Cloner cloner)
57      : base(original, cloner) { }
58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new ClassificationPerformanceMeasuresResultCollection(this, cloner);
60    }
61
62    #region result properties
63    public string ClassificationPositiveClassName {
64      get { return ((StringValue)this[ClassificationPositiveClassNameResultName].Value).Value; }
65      set { ((StringValue)this[ClassificationPositiveClassNameResultName].Value).Value = value; }
66    }
67    public double TrainingTruePositiveRate {
68      get { return ((DoubleValue)this[TrainingTruePositiveRateResultName].Value).Value; }
69      set { ((DoubleValue)this[TrainingTruePositiveRateResultName].Value).Value = value; }
70    }
71    public double TrainingTrueNegativeRate {
72      get { return ((DoubleValue)this[TrainingTrueNegativeRateResultName].Value).Value; }
73      set { ((DoubleValue)this[TrainingTrueNegativeRateResultName].Value).Value = value; }
74    }
75    public double TrainingPositivePredictiveValue {
76      get { return ((DoubleValue)this[TrainingPositivePredictiveValueResultName].Value).Value; }
77      set { ((DoubleValue)this[TrainingPositivePredictiveValueResultName].Value).Value = value; }
78    }
79    public double TrainingNegativePredictiveValue {
80      get { return ((DoubleValue)this[TrainingNegativePredictiveValueResultName].Value).Value; }
81      set { ((DoubleValue)this[TrainingNegativePredictiveValueResultName].Value).Value = value; }
82    }
83    public double TrainingFalsePositiveRate {
84      get { return ((DoubleValue)this[TrainingFalsePositiveRateResultName].Value).Value; }
85      set { ((DoubleValue)this[TrainingFalsePositiveRateResultName].Value).Value = value; }
86    }
87    public double TrainingFalseDiscoveryRate {
88      get { return ((DoubleValue)this[TrainingFalseDiscoveryRateResultName].Value).Value; }
89      set { ((DoubleValue)this[TrainingFalseDiscoveryRateResultName].Value).Value = value; }
90    }
91    public double TestTruePositiveRate {
92      get { return ((DoubleValue)this[TestTruePositiveRateResultName].Value).Value; }
93      set { ((DoubleValue)this[TestTruePositiveRateResultName].Value).Value = value; }
94    }
95    public double TestTrueNegativeRate {
96      get { return ((DoubleValue)this[TestTrueNegativeRateResultName].Value).Value; }
97      set { ((DoubleValue)this[TestTrueNegativeRateResultName].Value).Value = value; }
98    }
99    public double TestPositivePredictiveValue {
100      get { return ((DoubleValue)this[TestPositivePredictiveValueResultName].Value).Value; }
101      set { ((DoubleValue)this[TestPositivePredictiveValueResultName].Value).Value = value; }
102    }
103    public double TestNegativePredictiveValue {
104      get { return ((DoubleValue)this[TestNegativePredictiveValueResultName].Value).Value; }
105      set { ((DoubleValue)this[TestNegativePredictiveValueResultName].Value).Value = value; }
106    }
107    public double TestFalsePositiveRate {
108      get { return ((DoubleValue)this[TestFalsePositiveRateResultName].Value).Value; }
109      set { ((DoubleValue)this[TestFalsePositiveRateResultName].Value).Value = value; }
110    }
111    public double TestFalseDiscoveryRate {
112      get { return ((DoubleValue)this[TestFalseDiscoveryRateResultName].Value).Value; }
113      set { ((DoubleValue)this[TestFalseDiscoveryRateResultName].Value).Value = value; }
114    }
115    #endregion
116
117    protected void AddMeasures() {
118      Add(new Result(ClassificationPositiveClassNameResultName, "The positive class which is used for the performance measure calculations.", new StringValue()));
119      Add(new Result(TrainingTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the training partition\n(TP/(TP+FN)).", new PercentValue()));
120      Add(new Result(TrainingTrueNegativeRateResultName, "Specificity/True negative rate of the model on the training partition\n(TN/(FP+TN)).", new PercentValue()));
121      Add(new Result(TrainingPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the training partition\n(TP/(TP+FP)).", new PercentValue()));
122      Add(new Result(TrainingNegativePredictiveValueResultName, "Negative predictive value of the model on the training partition\n(TN/(TN+FN)).", new PercentValue()));
123      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()));
124      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()));
125      Add(new Result(TestTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the test partition\n(TP/(TP+FN)).", new PercentValue()));
126      Add(new Result(TestTrueNegativeRateResultName, "Specificity/True negative rate of the model on the test partition\n(TN/(FP+TN)).", new PercentValue()));
127      Add(new Result(TestPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the test partition\n(TP/(TP+FP)).", new PercentValue()));
128      Add(new Result(TestNegativePredictiveValueResultName, "Negative predictive value of the model on the test partition\n(TN/(TN+FN)).", new PercentValue()));
129      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()));
130      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()));
131      TrainingTruePositiveRate = double.NaN;
132      TrainingTrueNegativeRate = double.NaN;
133      TrainingPositivePredictiveValue = double.NaN;
134      TrainingNegativePredictiveValue = double.NaN;
135      TrainingFalsePositiveRate = double.NaN;
136      TrainingFalseDiscoveryRate = double.NaN;
137      TestTruePositiveRate = double.NaN;
138      TestTrueNegativeRate = double.NaN;
139      TestPositivePredictiveValue = double.NaN;
140      TestNegativePredictiveValue = double.NaN;
141      TestFalsePositiveRate = double.NaN;
142      TestFalseDiscoveryRate = double.NaN;
143    }
144
145    public void SetTrainingResults(ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator) {
146      if (!string.IsNullOrWhiteSpace(ClassificationPositiveClassName)
147              && !ClassificationPositiveClassName.Equals(trainingPerformanceCalculator.PositiveClassName))
148        throw new ArgumentException("Classification positive class of the training data doesn't match with the data of test partition.");
149      ClassificationPositiveClassName = trainingPerformanceCalculator.PositiveClassName;
150      TrainingTruePositiveRate = trainingPerformanceCalculator.TruePositiveRate;
151      TrainingTrueNegativeRate = trainingPerformanceCalculator.TrueNegativeRate;
152      TrainingPositivePredictiveValue = trainingPerformanceCalculator.PositivePredictiveValue;
153      TrainingNegativePredictiveValue = trainingPerformanceCalculator.NegativePredictiveValue;
154      TrainingFalsePositiveRate = trainingPerformanceCalculator.FalsePositiveRate;
155      TrainingFalseDiscoveryRate = trainingPerformanceCalculator.FalseDiscoveryRate;
156    }
157
158    public void SetTestResults(ClassificationPerformanceMeasuresCalculator testPerformanceCalculator) {
159      if (!string.IsNullOrWhiteSpace(ClassificationPositiveClassName)
160                && !ClassificationPositiveClassName.Equals(testPerformanceCalculator.PositiveClassName))
161        throw new ArgumentException("Classification positive class of the test data doesn't match with the data of training partition.");
162      ClassificationPositiveClassName = testPerformanceCalculator.PositiveClassName;
163      TestTruePositiveRate = testPerformanceCalculator.TruePositiveRate;
164      TestTrueNegativeRate = testPerformanceCalculator.TrueNegativeRate;
165      TestPositivePredictiveValue = testPerformanceCalculator.PositivePredictiveValue;
166      TestNegativePredictiveValue = testPerformanceCalculator.NegativePredictiveValue;
167      TestFalsePositiveRate = testPerformanceCalculator.FalsePositiveRate;
168      TestFalseDiscoveryRate = testPerformanceCalculator.FalseDiscoveryRate;
169    }
170  }
171}
Note: See TracBrowser for help on using the repository browser.