Changeset 13103
- Timestamp:
- 11/03/15 07:12:27 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ConfusionMatrixCalculator.cs
r13102 r13103 27 27 public class ConfusionMatrixCalculator { 28 28 public static double[,] Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 29 if (originalValues.Count() != estimatedValues.Count()) {30 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");31 }32 33 var classValues = originalValues.Distinct().ToList();34 var estimatedClassValues = estimatedValues.Distinct().ToList();35 36 if (!estimatedClassValues.All(x => classValues.Contains(x))) {37 errorState = OnlineCalculatorError.InvalidValueAdded;38 return null;39 }40 41 int classes = classValues.Count;42 double[,] confusionMatrix = new double[classes, classes];43 29 44 30 Dictionary<double, int> classValueIndexMapping = new Dictionary<double, int>(); 45 31 int index = 0; 46 foreach (double classValue in classValues.OrderBy(x => x)) { 47 classValueIndexMapping.Add(classValue, index); 48 index++; 32 foreach (double classValue in originalValues.OrderBy(x => x)) { 33 if (!classValueIndexMapping.ContainsKey(classValue)) { 34 classValueIndexMapping.Add(classValue, index); 35 index++; 36 } 49 37 } 38 39 int classes = classValueIndexMapping.Count; 40 double[,] confusionMatrix = new double[classes, classes]; 41 50 42 51 43 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); … … 66 58 } 67 59 60 if (originalEnumerator.MoveNext() || estimatedEnumerator.MoveNext()) { 61 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 62 63 } 64 68 65 errorState = OnlineCalculatorError.None; 69 66 return confusionMatrix; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/FOneScoreCalculator.cs
r13102 r13103 28 28 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 29 29 if (originalValues.Distinct().Skip(2).Any()) { 30 // TODO: we could use ClassificationPerformanceMeasuresCalculator instead of the ConfusionMatrixCalculator below to handle multi-class problems 30 31 throw new ArgumentException("F1 score can only be calculated for binary classification."); 31 32 }
Note: See TracChangeset
for help on using the changeset viewer.