Changeset 9363 for branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs
- Timestamp:
- 04/16/13 13:13:41 (11 years ago)
- Location:
- branches/OaaS
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 23 24 packages
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/OaaS/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs
r8126 r9363 53 53 54 54 public static void CalculateThresholds(IClassificationProblemData problemData, IEnumerable<double> estimatedValues, IEnumerable<double> targetClassValues, out double[] classValues, out double[] thresholds) { 55 int slices = 100;56 double minThresholdInc = 10e-5; // necessary to prevent infinite loop when maxEstimated - minEstimated is effectively zero (constant model)55 const int slices = 100; 56 const double minThresholdInc = 10e-5; // necessary to prevent infinite loop when maxEstimated - minEstimated is effectively zero (constant model) 57 57 List<double> estimatedValuesList = estimatedValues.ToList(); 58 58 double maxEstimatedValue = estimatedValuesList.Max(); … … 61 61 var estimatedAndTargetValuePairs = 62 62 estimatedValuesList.Zip(targetClassValues, (x, y) => new { EstimatedValue = x, TargetClassValue = y }) 63 .OrderBy(x => x.EstimatedValue) 64 .ToList(); 63 .OrderBy(x => x.EstimatedValue).ToList(); 65 64 66 classValues = problemData.ClassValues.OrderBy(x => x).ToArray(); 65 classValues = estimatedAndTargetValuePairs.GroupBy(x => x.TargetClassValue) 66 .Select(x => new { Median = x.Select(y => y.EstimatedValue).Median(), Class = x.Key }) 67 .OrderBy(x => x.Median).Select(x => x.Class).ToArray(); 68 67 69 int nClasses = classValues.Length; 68 70 thresholds = new double[nClasses]; 69 71 thresholds[0] = double.NegativeInfinity; 70 // thresholds[thresholds.Length - 1] = double.PositiveInfinity;71 72 72 73 // incrementally calculate accuracy of all possible thresholds … … 85 86 //all positives 86 87 if (pair.TargetClassValue.IsAlmost(classValues[i - 1])) { 87 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold)88 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold) 88 89 //true positive 89 classificationScore += problemData.GetClassificationPenalty( classValues[i - 1], classValues[i - 1]);90 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue); 90 91 else 91 92 //false negative 92 classificationScore += problemData.GetClassificationPenalty( classValues[i], classValues[i - 1]);93 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]); 93 94 } 94 95 //all negatives 95 96 else { 96 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold) 97 //false positive 98 classificationScore += problemData.GetClassificationPenalty(classValues[i - 1], classValues[i]); 99 else 100 //true negative, consider only upper class 101 classificationScore += problemData.GetClassificationPenalty(classValues[i], classValues[i]); 97 //false positive 98 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold) 99 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 1]); 100 else if (pair.EstimatedValue <= lowerThreshold) 101 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 2]); 102 else if (pair.EstimatedValue > actualThreshold) { 103 if (pair.TargetClassValue < classValues[i - 1]) //negative in wrong class, consider upper class 104 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]); 105 else //true negative, must be optimized by the other thresholds 106 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue); 107 } 102 108 } 103 109 }
Note: See TracChangeset
for help on using the changeset viewer.