- Timestamp:
- 09/14/09 17:30:02 (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Modeling/3.2/SimpleConfusionMatrixEvaluator.cs
r2348 r2351 23 23 using HeuristicLab.Data; 24 24 25 namespace HeuristicLab. GP.StructureIdentification.Classification{26 public class ConfusionMatrixEvaluator : GPClassificationEvaluatorBase {25 namespace HeuristicLab.Modeling { 26 public class SimpleConfusionMatrixEvaluator : OperatorBase { 27 27 public override string Description { 28 28 get { … … 31 31 } 32 32 33 public ConfusionMatrixEvaluator()33 public SimpleConfusionMatrixEvaluator() 34 34 : base() { 35 AddVariableInfo(new VariableInfo("Values", "Original and predicted target values generated by a model", typeof(DoubleMatrixData), VariableKind.In)); 35 36 AddVariableInfo(new VariableInfo("ConfusionMatrix", "The confusion matrix of the model", typeof(IntMatrixData), VariableKind.New)); 36 37 } 37 38 38 public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) { 39 public override IOperation Apply(IScope scope) { 40 double[,] values = GetVariableValue<DoubleMatrixData>("Values", scope, true).Data; 41 int[,] confusionMatrix = Calculate(values); 39 42 IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false); 40 43 if (matrix == null) { 41 matrix = new IntMatrixData( new int[classes.Length, classes.Length]);44 matrix = new IntMatrixData(confusionMatrix); 42 45 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("ConfusionMatrix"), matrix)); 43 46 } 44 47 45 int nSamples = end - start; 46 for (int sample = start; sample < end; sample++) { 47 double est = evaluator.Evaluate(sample); 48 double origClass = dataset.GetValue(sample, targetVariable); 48 return null; 49 } 50 51 public static int[,] Calculate(double[,] values) { 52 double[] classes = SimpleAccuracyEvaluator.CalculateTargetClasses(values); 53 double[] thresholds = SimpleAccuracyEvaluator.CalculateThresholds(classes); 54 int nSamples = values.GetLength(0); 55 int[,] confusionMatrix = new int[classes.Length, classes.Length]; 56 for (int sample = 0; sample < nSamples; sample++) { 57 double est = values[sample, 0]; 58 double origClass = values[sample, 1]; 49 59 int estClassIndex = -1; 50 60 // if estimation is lower than the smallest threshold value -> estimated class is the lower class … … 70 80 } 71 81 } 72 matrix.Data[origClassIndex, estClassIndex]++;82 confusionMatrix[origClassIndex, estClassIndex]++; 73 83 } 84 return confusionMatrix; 74 85 } 75 86 }
Note: See TracChangeset
for help on using the changeset viewer.