Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11683


Ignore:
Timestamp:
12/14/14 23:20:12 (9 years ago)
Author:
ehopf
Message:

#2278

  • Classification performance measures improvements in terms of readability of the code.
  • Added positive class value to the classification performance measures result collection.
  • Fixed bug: classification performance measures will now be calculated after loading from files with non serialized performance measures results.
Location:
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4
Files:
1 added
1 deleted
2 edited

Legend:

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

    r11643 r11683  
    229229    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" />
    230230    <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" />
     231    <Compile Include="OnlineCalculators\ClassificationPerformanceMeasuresCalculator.cs" />
    231232    <Compile Include="OnlineCalculators\DependencyCalculator\HoeffdingsDependenceCalculator.cs" />
    232233    <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRDependenceCalculator.cs" />
  • branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r11622 r11683  
    3535    private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)";
    3636
     37    private const string ClassificationPositiveClassValueResultName = "Classification positive class";
    3738    private const string TrainingTruePositiveRateResultName = "True positive rate (training)";
    3839    private const string TrainingTrueNegativeRateResultName = "True negative rate (training)";
     
    4748    private const string TestFalsePositiveRateResultName = "False positive rate (test)";
    4849    private const string TestFalseDiscoveryRateResultName = "False discovery rate (test)";
    49     private const string QualityMeasuresResultName = "Classification Quality Measures";
     50    private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures";
    5051
    5152    public new IClassificationModel Model {
     
    7778    }
    7879
    79     #region Quality Measures
    80     public ResultCollection QualityMeasures {
    81       get { return ((ResultCollection)this[QualityMeasuresResultName].Value); }
    82       protected set { (this[QualityMeasuresResultName].Value) = value; }
    83     }
    84 
     80    #region Classification performance measures
     81    public ResultCollection ClassificationPerformanceMeasures {
     82      get { return ((ResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); }
     83      protected set { (this[ClassificationPerformanceMeasuresResultName].Value) = value; }
     84    }
     85
     86    public string ClassificationPositiveClassValue {
     87      get { return ((StringValue)ClassificationPerformanceMeasures[ClassificationPositiveClassValueResultName].Value).Value; }
     88      protected set { ((StringValue)ClassificationPerformanceMeasures[ClassificationPositiveClassValueResultName].Value).Value = value; }
     89    }
    8590    public double TrainingTruePositiveRate {
    86       get { return ((DoubleValue)QualityMeasures[TrainingTruePositiveRateResultName].Value).Value; }
    87       protected set { ((DoubleValue)QualityMeasures[TrainingTruePositiveRateResultName].Value).Value = value; }
    88     }
    89     public double TrainingTrueNegativeRate {
    90       get { return ((DoubleValue)QualityMeasures[TrainingTrueNegativeRateResultName].Value).Value; }
    91       protected set { ((DoubleValue)QualityMeasures[TrainingTrueNegativeRateResultName].Value).Value = value; }
     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; }
    9297    }
    9398    public double TrainingPositivePredictiveValue {
    94       get { return ((DoubleValue)QualityMeasures[TrainingPositivePredictiveValueResultName].Value).Value; }
    95       protected set { ((DoubleValue)QualityMeasures[TrainingPositivePredictiveValueResultName].Value).Value = value; }
     99      get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingPositivePredictiveValueResultName].Value).Value; }
     100      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingPositivePredictiveValueResultName].Value).Value = value; }
    96101    }
    97102    public double TrainingNegativePredictiveValue {
    98       get { return ((DoubleValue)QualityMeasures[TrainingNegativePredictiveValueResultName].Value).Value; }
    99       protected set { ((DoubleValue)QualityMeasures[TrainingNegativePredictiveValueResultName].Value).Value = value; }
     103      get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingNegativePredictiveValueResultName].Value).Value; }
     104      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingNegativePredictiveValueResultName].Value).Value = value; }
    100105    }
    101106    public double TrainingFalsePositiveRate {
    102       get { return ((DoubleValue)QualityMeasures[TrainingFalsePositiveRateResultName].Value).Value; }
    103       protected set { ((DoubleValue)QualityMeasures[TrainingFalsePositiveRateResultName].Value).Value = value; }
     107      get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalsePositiveRateResultName].Value).Value; }
     108      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalsePositiveRateResultName].Value).Value = value; }
    104109    }
    105110    public double TrainingFalseDiscoveryRate {
    106       get { return ((DoubleValue)QualityMeasures[TrainingFalseDiscoveryRateResultName].Value).Value; }
    107       protected set { ((DoubleValue)QualityMeasures[TrainingFalseDiscoveryRateResultName].Value).Value = value; }
    108     }
    109 
     111      get { return ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalseDiscoveryRateResultName].Value).Value; }
     112      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TrainingFalseDiscoveryRateResultName].Value).Value = value; }
     113    }
    110114    public double TestTruePositiveRate {
    111       get { return ((DoubleValue)QualityMeasures[TestTruePositiveRateResultName].Value).Value; }
    112       protected set { ((DoubleValue)QualityMeasures[TestTruePositiveRateResultName].Value).Value = value; }
     115      get { return ((DoubleValue)ClassificationPerformanceMeasures[TestTruePositiveRateResultName].Value).Value; }
     116      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestTruePositiveRateResultName].Value).Value = value; }
    113117    }
    114118    public double TestTrueNegativeRate {
    115       get { return ((DoubleValue)QualityMeasures[TestTrueNegativeRateResultName].Value).Value; }
    116       protected set { ((DoubleValue)QualityMeasures[TestTrueNegativeRateResultName].Value).Value = value; }
     119      get { return ((DoubleValue)ClassificationPerformanceMeasures[TestTrueNegativeRateResultName].Value).Value; }
     120      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestTrueNegativeRateResultName].Value).Value = value; }
    117121    }
    118122    public double TestPositivePredictiveValue {
    119       get { return ((DoubleValue)QualityMeasures[TestPositivePredictiveValueResultName].Value).Value; }
    120       protected set { ((DoubleValue)QualityMeasures[TestPositivePredictiveValueResultName].Value).Value = value; }
     123      get { return ((DoubleValue)ClassificationPerformanceMeasures[TestPositivePredictiveValueResultName].Value).Value; }
     124      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestPositivePredictiveValueResultName].Value).Value = value; }
    121125    }
    122126    public double TestNegativePredictiveValue {
    123       get { return ((DoubleValue)QualityMeasures[TestNegativePredictiveValueResultName].Value).Value; }
    124       protected set { ((DoubleValue)QualityMeasures[TestNegativePredictiveValueResultName].Value).Value = value; }
     127      get { return ((DoubleValue)ClassificationPerformanceMeasures[TestNegativePredictiveValueResultName].Value).Value; }
     128      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestNegativePredictiveValueResultName].Value).Value = value; }
    125129    }
    126130    public double TestFalsePositiveRate {
    127       get { return ((DoubleValue)QualityMeasures[TestFalsePositiveRateResultName].Value).Value; }
    128       protected set { ((DoubleValue)QualityMeasures[TestFalsePositiveRateResultName].Value).Value = value; }
     131      get { return ((DoubleValue)ClassificationPerformanceMeasures[TestFalsePositiveRateResultName].Value).Value; }
     132      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestFalsePositiveRateResultName].Value).Value = value; }
    129133    }
    130134    public double TestFalseDiscoveryRate {
    131       get { return ((DoubleValue)QualityMeasures[TestFalseDiscoveryRateResultName].Value).Value; }
    132       protected set { ((DoubleValue)QualityMeasures[TestFalseDiscoveryRateResultName].Value).Value = value; }
     135      get { return ((DoubleValue)ClassificationPerformanceMeasures[TestFalseDiscoveryRateResultName].Value).Value; }
     136      protected set { ((DoubleValue)ClassificationPerformanceMeasures[TestFalseDiscoveryRateResultName].Value).Value = value; }
    133137    }
    134138    #endregion
     
    146150      Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue()));
    147151      Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
    148       AddQualityMeasuresResultCollection();
     152      AddClassificationPerformanceMeasuresResultCollection();
    149153    }
    150154
     
    155159      if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName))
    156160        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
    157       if (!this.ContainsKey(QualityMeasuresResultName))
    158         AddQualityMeasuresResultCollection();
    159     }
    160 
    161     protected void AddQualityMeasuresResultCollection() {
    162       ResultCollection qualityMeasuresResult = new ResultCollection();
    163       qualityMeasuresResult.Add(new Result(TrainingTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the training partition\n(TP/(TP+FN)).", new PercentValue()));
    164       qualityMeasuresResult.Add(new Result(TrainingTrueNegativeRateResultName, "Specificity/True negative rate of the model on the training partition\n(TN/(FP+TN)).", new PercentValue()));
    165       qualityMeasuresResult.Add(new Result(TrainingPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the training partition\n(TP/(TP+FP)).", new PercentValue()));
    166       qualityMeasuresResult.Add(new Result(TrainingNegativePredictiveValueResultName, "Negative predictive value of the model on the training partition\n(TN/(TN+FN)).", new PercentValue()));
    167       qualityMeasuresResult.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()));
    168       qualityMeasuresResult.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()));
    169       qualityMeasuresResult.Add(new Result(TestTruePositiveRateResultName, "Sensitivity/True positive rate of the model on the test partition\n(TP/(TP+FN)).", new PercentValue()));
    170       qualityMeasuresResult.Add(new Result(TestTrueNegativeRateResultName, "Specificity/True negative rate of the model on the test partition\n(TN/(FP+TN)).", new PercentValue()));
    171       qualityMeasuresResult.Add(new Result(TestPositivePredictiveValueResultName, "Precision/Positive predictive value of the model on the test partition\n(TP/(TP+FP)).", new PercentValue()));
    172       qualityMeasuresResult.Add(new Result(TestNegativePredictiveValueResultName, "Negative predictive value of the model on the test partition\n(TN/(TN+FN)).", new PercentValue()));
    173       qualityMeasuresResult.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()));
    174       qualityMeasuresResult.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()));
    175       Add(new Result(QualityMeasuresResultName, "Classification quality measures.\nIn Multiclass Classification all misclassifications of the negative class will be treated as true negatives.", qualityMeasuresResult));
     161      if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) {
     162        AddClassificationPerformanceMeasuresResultCollection();
     163        RecalculateResults();
     164      }
     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));
    176184    }
    177185
     
    185193      var positiveClassName = ProblemData.PositiveClassName;
    186194      double positiveClassValue = ProblemData.GetClassValue(positiveClassName);
    187       QualityCalculator trainingQualityCalculator = new QualityCalculator(positiveClassValue);
    188       QualityCalculator testQualityCalculator = new QualityCalculator(positiveClassValue);
     195      ClassificationPositiveClassValue = positiveClassName;
     196      ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassValue);
     197      ClassificationPerformanceMeasuresCalculator testPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassValue);
    189198
    190199      OnlineCalculatorError errorState;
     
    205214      TestNormalizedGiniCoefficient = testNormalizedGini;
    206215
    207       //quality measures training partition
    208       trainingQualityCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState);
     216      //performance measures training partition
     217      trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState);
    209218      if (errorState != OnlineCalculatorError.None) {
    210219        TrainingTruePositiveRate = double.NaN;
     
    215224        TrainingFalseDiscoveryRate = double.NaN;
    216225      } else {
    217         TrainingTruePositiveRate = trainingQualityCalculator.TruePositiveRate;
    218         TrainingTrueNegativeRate = trainingQualityCalculator.TrueNegativeRate;
    219         TrainingPositivePredictiveValue = trainingQualityCalculator.PositivePredictiveValue;
    220         TrainingNegativePredictiveValue = trainingQualityCalculator.NegativePredictiveValue;
    221         TrainingFalsePositiveRate = trainingQualityCalculator.FalsePositiveRate;
    222         TrainingFalseDiscoveryRate = trainingQualityCalculator.FalseDiscoveryRate;
     226        TrainingTruePositiveRate = trainingPerformanceCalculator.TruePositiveRate;
     227        TrainingTrueNegativeRate = trainingPerformanceCalculator.TrueNegativeRate;
     228        TrainingPositivePredictiveValue = trainingPerformanceCalculator.PositivePredictiveValue;
     229        TrainingNegativePredictiveValue = trainingPerformanceCalculator.NegativePredictiveValue;
     230        TrainingFalsePositiveRate = trainingPerformanceCalculator.FalsePositiveRate;
     231        TrainingFalseDiscoveryRate = trainingPerformanceCalculator.FalseDiscoveryRate;
    223232      }
    224       //quality measures test partition
    225       testQualityCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState);
     233      //performance measures test partition
     234      testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState);
    226235      if (errorState != OnlineCalculatorError.None) {
    227236        TestTruePositiveRate = double.NaN;
     
    232241        TestFalseDiscoveryRate = double.NaN;
    233242      } else {
    234         TestTruePositiveRate = testQualityCalculator.TruePositiveRate;
    235         TestTrueNegativeRate = testQualityCalculator.TrueNegativeRate;
    236         TestPositivePredictiveValue = testQualityCalculator.PositivePredictiveValue;
    237         TestNegativePredictiveValue = testQualityCalculator.NegativePredictiveValue;
    238         TestFalsePositiveRate = testQualityCalculator.FalsePositiveRate;
    239         TestFalseDiscoveryRate = testQualityCalculator.FalseDiscoveryRate;
     243        TestTruePositiveRate = testPerformanceCalculator.TruePositiveRate;
     244        TestTrueNegativeRate = testPerformanceCalculator.TrueNegativeRate;
     245        TestPositivePredictiveValue = testPerformanceCalculator.PositivePredictiveValue;
     246        TestNegativePredictiveValue = testPerformanceCalculator.NegativePredictiveValue;
     247        TestFalsePositiveRate = testPerformanceCalculator.FalsePositiveRate;
     248        TestFalseDiscoveryRate = testPerformanceCalculator.FalseDiscoveryRate;
    240249      }
    241250    }
Note: See TracChangeset for help on using the changeset viewer.