Changeset 11761 for branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ClassificationPerformanceMeasuresCalculator.cs
- Timestamp:
- 01/15/15 11:16:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ClassificationPerformanceMeasuresCalculator.cs
r11685 r11761 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 using System.Text;26 24 using HeuristicLab.Common; 27 25 … … 32 30 this.positiveClassName = positiveClassName; 33 31 this.positiveClassValue = positiveClassValue; 34 Reset(); 32 Reset(); 35 33 } 36 34 37 35 #region Properties 38 private string positiveClassName;39 private double positiveClassValue;40 36 private int truePositiveCount, falsePositiveCount, trueNegativeCount, falseNegativeCount; 41 37 38 private readonly string positiveClassName; 42 39 public string PositiveClassName { 43 get { 44 return positiveClassName; 45 } 40 get { return positiveClassName; } 46 41 } 42 43 private readonly double positiveClassValue; 47 44 public double PositiveClassValue { 48 get { 49 return positiveClassValue; 50 } 45 get { return positiveClassValue; } 51 46 } 52 47 public double TruePositiveRate { … … 92 87 } 93 88 #endregion 94 89 95 90 public void Reset() { 96 91 truePositiveCount = 0; … … 103 98 public void Add(double originalClassValue, double estimatedClassValue) { 104 99 // ignore cases where original is NaN completely 105 if (!double.IsNaN(originalClassValue)) { 106 if (originalClassValue.IsAlmost(positiveClassValue) 107 || estimatedClassValue.IsAlmost(positiveClassValue)) { //positive class/positive class estimation 108 if (estimatedClassValue.IsAlmost(originalClassValue)) { 109 truePositiveCount++; 110 } else { 111 if (estimatedClassValue.IsAlmost(positiveClassValue)) //misclassification of the negative class 112 falsePositiveCount++; 113 else //misclassification of the positive class 114 falseNegativeCount++; 115 } 116 } else { //negative class/negative class estimation 117 //In a multiclass classification all misclassifications of the negative class 118 //will be treated as true negatives except on positive class estimations 119 trueNegativeCount++; 100 if (double.IsNaN(originalClassValue)) return; 101 102 if (originalClassValue.IsAlmost(positiveClassValue) 103 || estimatedClassValue.IsAlmost(positiveClassValue)) { //positive class/positive class estimation 104 if (estimatedClassValue.IsAlmost(originalClassValue)) { 105 truePositiveCount++; 106 } else { 107 if (estimatedClassValue.IsAlmost(positiveClassValue)) //misclassification of the negative class 108 falsePositiveCount++; 109 else //misclassification of the positive class 110 falseNegativeCount++; 120 111 } 121 errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1 112 } else { //negative class/negative class estimation 113 //In a multiclass classification all misclassifications of the negative class 114 //will be treated as true negatives except on positive class estimations 115 trueNegativeCount++; 122 116 } 117 118 errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1 123 119 } 124 120 125 public void Calculate(IEnumerable<double> originalClassValues, IEnumerable<double> estimatedClassValues, 126 out OnlineCalculatorError errorState) { 121 public void Calculate(IEnumerable<double> originalClassValues, IEnumerable<double> estimatedClassValues) { 127 122 IEnumerator<double> originalEnumerator = originalClassValues.GetEnumerator(); 128 123 IEnumerator<double> estimatedEnumerator = estimatedClassValues.GetEnumerator(); … … 137 132 138 133 // check if both enumerators are at the end to make sure both enumerations have the same length 139 if (ErrorState == OnlineCalculatorError.None && 140 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 134 if (ErrorState == OnlineCalculatorError.None && (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 141 135 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 142 } else {143 errorState = ErrorState;144 136 } 137 errorState = ErrorState; 145 138 } 146 139 }
Note: See TracChangeset
for help on using the changeset viewer.