Changeset 11684


Ignore:
Timestamp:
12/15/14 01:20:08 (8 years ago)
Author:
ehopf
Message:

#2278: Encapsulated the classification performance measures to the ClassificationPerformanceMeasuresResultCollection

Location:
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r11683 r11684  
    175175    </Compile>
    176176    <Compile Include="Implementation\Classification\ClassificationEnsembleSolution.cs" />
     177    <Compile Include="Implementation\Classification\ClassificationPerformanceMeasuresResultCollection.cs" />
    177178    <Compile Include="Implementation\Classification\ClassificationProblemData.cs" />
    178179    <Compile Include="Implementation\Classification\ClassificationProblem.cs" />
  • branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r11683 r11684  
    3434    private const string TrainingNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (training)";
    3535    private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)";
    36 
    37     private const string ClassificationPositiveClassValueResultName = "Classification positive class";
    38     private const string TrainingTruePositiveRateResultName = "True positive rate (training)";
    39     private const string TrainingTrueNegativeRateResultName = "True negative rate (training)";
    40     private const string TrainingPositivePredictiveValueResultName = "Positive predictive value (training)";
    41     private const string TrainingNegativePredictiveValueResultName = "Negative predictive value (training)";
    42     private const string TrainingFalsePositiveRateResultName = "False positive rate (training)";
    43     private const string TrainingFalseDiscoveryRateResultName = "False discovery rate (training)";
    44     private const string TestTruePositiveRateResultName = "True positive rate (test)";
    45     private const string TestTrueNegativeRateResultName = "True negative rate (test)";
    46     private const string TestPositivePredictiveValueResultName = "Positive predictive value (test)";
    47     private const string TestNegativePredictiveValueResultName = "Negative predictive value (test)";
    48     private const string TestFalsePositiveRateResultName = "False positive rate (test)";
    49     private const string TestFalseDiscoveryRateResultName = "False discovery rate (test)";
    5036    private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures";
    5137
     
    7763      protected set { ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value = value; }
    7864    }
    79 
    80     #region Classification performance measures
    81     public ResultCollection ClassificationPerformanceMeasures {
    82       get { return ((ResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); }
     65    public ClassificationPerformanceMeasuresResultCollection ClassificationPerformanceMeasures {
     66      get { return ((ClassificationPerformanceMeasuresResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); }
    8367      protected set { (this[ClassificationPerformanceMeasuresResultName].Value) = value; }
    8468    }
    85 
    86     public string ClassificationPositiveClassValue {
    87       get { return ((StringValue)ClassificationPerformanceMeasures[ClassificationPositiveClassValueResultName].Value).Value; }
    88       protected set { ((StringValue)ClassificationPerformanceMeasures[ClassificationPositiveClassValueResultName].Value).Value = value; }
    89     }
    90     public double TrainingTruePositiveRate {
    91       get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingTruePositiveRateResultName].Value).Value; }
    92       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingTruePositiveRateResultName].Value).Value = value; }
    93     }
    94     public double TrainingTrueNegativeRate { 
    95       get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingTrueNegativeRateResultName].Value).Value; }
    96       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingTrueNegativeRateResultName].Value).Value = value; }
    97     }
    98     public double TrainingPositivePredictiveValue {
    99       get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingPositivePredictiveValueResultName].Value).Value; }
    100       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingPositivePredictiveValueResultName].Value).Value = value; }
    101     }
    102     public double TrainingNegativePredictiveValue {
    103       get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingNegativePredictiveValueResultName].Value).Value; }
    104       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingNegativePredictiveValueResultName].Value).Value = value; }
    105     }
    106     public double TrainingFalsePositiveRate {
    107       get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalsePositiveRateResultName].Value).Value; }
    108       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalsePositiveRateResultName].Value).Value = value; }
    109     }
    110     public double TrainingFalseDiscoveryRate {
    111       get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalseDiscoveryRateResultName].Value).Value; }
    112       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalseDiscoveryRateResultName].Value).Value = value; }
    113     }
    114     public double TestTruePositiveRate {
    115       get { return ((DoubleValue)ClassificationPerformanceMeasures[TestTruePositiveRateResultName].Value).Value; }
    116       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestTruePositiveRateResultName].Value).Value = value; }
    117     }
    118     public double TestTrueNegativeRate {
    119       get { return ((DoubleValue)ClassificationPerformanceMeasures[TestTrueNegativeRateResultName].Value).Value; }
    120       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestTrueNegativeRateResultName].Value).Value = value; }
    121     }
    122     public double TestPositivePredictiveValue {
    123       get { return ((DoubleValue)ClassificationPerformanceMeasures[TestPositivePredictiveValueResultName].Value).Value; }
    124       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestPositivePredictiveValueResultName].Value).Value = value; }
    125     }
    126     public double TestNegativePredictiveValue {
    127       get { return ((DoubleValue)ClassificationPerformanceMeasures[TestNegativePredictiveValueResultName].Value).Value; }
    128       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestNegativePredictiveValueResultName].Value).Value = value; }
    129     }
    130     public double TestFalsePositiveRate {
    131       get { return ((DoubleValue)ClassificationPerformanceMeasures[TestFalsePositiveRateResultName].Value).Value; }
    132       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestFalsePositiveRateResultName].Value).Value = value; }
    133     }
    134     public double TestFalseDiscoveryRate {
    135       get { return ((DoubleValue)ClassificationPerformanceMeasures[TestFalseDiscoveryRateResultName].Value).Value; }
    136       protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestFalseDiscoveryRateResultName].Value).Value = value; }
    137     }
    138     #endregion
    13969    #endregion
    14070
     
    15080      Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue()));
    15181      Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
    152       AddClassificationPerformanceMeasuresResultCollection();
     82      Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
     83                              In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.",
     84                            new ClassificationPerformanceMeasuresResultCollection()));
    15385    }
    15486
     
    16092        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
    16193      if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) {
    162         AddClassificationPerformanceMeasuresResultCollection();
     94        Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
     95                              In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.",
     96                              new ClassificationPerformanceMeasuresResultCollection()));
    16397        RecalculateResults();
    16498      }
    165     }
    166 
    167     protected void AddClassificationPerformanceMeasuresResultCollection() {
    168       ResultCollection performanceMeasures = new ResultCollection();
    169       performanceMeasures.Add(new Result(ClassificationPositiveClassValueResultName, "The positive class which is used for the performance measure calculations.", new StringValue()));
    170       performanceMeasures.Add(new Result(TrainingTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the training partition\n(TP/(TP+FN)).", new PercentValue()));
    171       performanceMeasures.Add(new Result(TrainingTrueNegativeRateResultName, "Specificity/True negative rate of the model on the training partition\n(TN/(FP+TN)).", new PercentValue()));
    172       performanceMeasures.Add(new Result(TrainingPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the training partition\n(TP/(TP+FP)).", new PercentValue()));
    173       performanceMeasures.Add(new Result(TrainingNegativePredictiveValueResultName, "Negative predictive value of the model on the training partition\n(TN/(TN+FN)).", new PercentValue()));
    174       performanceMeasures.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()));
    175       performanceMeasures.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()));
    176       performanceMeasures.Add(new Result(TestTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the test partition\n(TP/(TP+FN)).", new PercentValue()));
    177       performanceMeasures.Add(new Result(TestTrueNegativeRateResultName, "Specificity/True negative rate of the model on the test partition\n(TN/(FP+TN)).", new PercentValue()));
    178       performanceMeasures.Add(new Result(TestPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the test partition\n(TP/(TP+FP)).", new PercentValue()));
    179       performanceMeasures.Add(new Result(TestNegativePredictiveValueResultName, "Negative predictive value of the model on the test partition\n(TN/(TN+FN)).", new PercentValue()));
    180       performanceMeasures.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()));
    181       performanceMeasures.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()));
    182       Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
    183                               In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", performanceMeasures));
    18499    }
    185100
     
    193108      var positiveClassName = ProblemData.PositiveClassName;
    194109      double positiveClassValue = ProblemData.GetClassValue(positiveClassName);
    195       ClassificationPositiveClassValue = positiveClassName;
     110      ClassificationPerformanceMeasures.ClassificationPositiveClassValue = positiveClassName;
    196111      ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassValue);
    197112      ClassificationPerformanceMeasuresCalculator testPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassValue);
     
    214129      TestNormalizedGiniCoefficient = testNormalizedGini;
    215130
    216       //performance measures training partition
    217131      trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState);
    218       if (errorState != OnlineCalculatorError.None) {
    219         TrainingTruePositiveRate = double.NaN;
    220         TrainingTrueNegativeRate = double.NaN;
    221         TrainingPositivePredictiveValue = double.NaN;
    222         TrainingNegativePredictiveValue = double.NaN;
    223         TrainingFalsePositiveRate = double.NaN;
    224         TrainingFalseDiscoveryRate = double.NaN;
    225       } else {
    226         TrainingTruePositiveRate = trainingPerformanceCalculator.TruePositiveRate;
    227         TrainingTrueNegativeRate = trainingPerformanceCalculator.TrueNegativeRate;
    228         TrainingPositivePredictiveValue = trainingPerformanceCalculator.PositivePredictiveValue;
    229         TrainingNegativePredictiveValue = trainingPerformanceCalculator.NegativePredictiveValue;
    230         TrainingFalsePositiveRate = trainingPerformanceCalculator.FalsePositiveRate;
    231         TrainingFalseDiscoveryRate = trainingPerformanceCalculator.FalseDiscoveryRate;
     132      if (errorState == OnlineCalculatorError.None) {
     133        ClassificationPerformanceMeasures.TrainingTruePositiveRate = trainingPerformanceCalculator.TruePositiveRate;
     134        ClassificationPerformanceMeasures.TrainingTrueNegativeRate = trainingPerformanceCalculator.TrueNegativeRate;
     135        ClassificationPerformanceMeasures.TrainingPositivePredictiveValue = trainingPerformanceCalculator.PositivePredictiveValue;
     136        ClassificationPerformanceMeasures.TrainingNegativePredictiveValue = trainingPerformanceCalculator.NegativePredictiveValue;
     137        ClassificationPerformanceMeasures.TrainingFalsePositiveRate = trainingPerformanceCalculator.FalsePositiveRate;
     138        ClassificationPerformanceMeasures.TrainingFalseDiscoveryRate = trainingPerformanceCalculator.FalseDiscoveryRate;
    232139      }
    233       //performance measures test partition
    234140      testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState);
    235       if (errorState != OnlineCalculatorError.None) {
    236         TestTruePositiveRate = double.NaN;
    237         TestTrueNegativeRate = double.NaN;
    238         TestPositivePredictiveValue = double.NaN;
    239         TestNegativePredictiveValue = double.NaN;
    240         TestFalsePositiveRate = double.NaN;
    241         TestFalseDiscoveryRate = double.NaN;
    242       } else {
    243         TestTruePositiveRate = testPerformanceCalculator.TruePositiveRate;
    244         TestTrueNegativeRate = testPerformanceCalculator.TrueNegativeRate;
    245         TestPositivePredictiveValue = testPerformanceCalculator.PositivePredictiveValue;
    246         TestNegativePredictiveValue = testPerformanceCalculator.NegativePredictiveValue;
    247         TestFalsePositiveRate = testPerformanceCalculator.FalsePositiveRate;
    248         TestFalseDiscoveryRate = testPerformanceCalculator.FalseDiscoveryRate;
     141      if (errorState == OnlineCalculatorError.None) {
     142        ClassificationPerformanceMeasures.TestTruePositiveRate = testPerformanceCalculator.TruePositiveRate;
     143        ClassificationPerformanceMeasures.TestTrueNegativeRate = testPerformanceCalculator.TrueNegativeRate;
     144        ClassificationPerformanceMeasures.TestPositivePredictiveValue = testPerformanceCalculator.PositivePredictiveValue;
     145        ClassificationPerformanceMeasures.TestNegativePredictiveValue = testPerformanceCalculator.NegativePredictiveValue;
     146        ClassificationPerformanceMeasures.TestFalsePositiveRate = testPerformanceCalculator.FalsePositiveRate;
     147        ClassificationPerformanceMeasures.TestFalseDiscoveryRate = testPerformanceCalculator.FalseDiscoveryRate;
    249148      }
    250149    }
Note: See TracChangeset for help on using the changeset viewer.