source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationPerformanceMeasures.cs @ 11763

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

#2278: Merged changes in HL.Problems.DataAnalysis into the trunk.

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