Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17962


Ignore:
Timestamp:
04/23/21 18:00:27 (4 years ago)
Author:
gkronber
Message:

#3120: create two separate results for Gini coefficients (one based on class values and one based on the discriminant function)

Location:
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r17180 r17962  
    3434    private const string TrainingAccuracyResultName = "Accuracy (training)";
    3535    private const string TestAccuracyResultName = "Accuracy (test)";
    36     private const string TrainingNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (training)";
    37     private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)";
     36    private const string TrainingNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (training)";
     37    private const string TestNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (test)";
    3838    private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures";
    3939
     
    9797      if (string.IsNullOrEmpty(Model.TargetVariable))
    9898        Model.TargetVariable = this.ProblemData.TargetVariable;
    99 
    100       if (!this.ContainsKey(TrainingNormalizedGiniCoefficientResultName))
     99      var newResult = false;
     100      if (!this.ContainsKey(TrainingNormalizedGiniCoefficientResultName)) {
    101101        Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue()));
    102       if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName))
     102        newResult = true;
     103      }
     104      if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName)) {
    103105        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
     106        newResult = true;
     107      }
    104108      if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) {
    105109        Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
    106110                              In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.",
    107111                              new ClassificationPerformanceMeasuresResultCollection()));
    108         CalculateClassificationResults();
     112        newResult = true;
    109113      }
     114      if (newResult) CalculateClassificationResults();
    110115    }
    111116
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r17180 r17962  
    4040    private const string TrainingRSquaredResultName = "Pearson's R² (training)";
    4141    private const string TestRSquaredResultName = "Pearson's R² (test)";
     42    private const string TrainingNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (training, discriminant values)";
     43    private const string TestNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (test, discriminant values)";
     44
    4245
    4346    public new IDiscriminantFunctionClassificationModel Model {
     
    7174      private set { ((DoubleValue)this[TestRSquaredResultName].Value).Value = value; }
    7275    }
     76    public double TrainingNormalizedGiniCoefficientForDiscriminantValues {
     77      get { return ((DoubleValue)this[TrainingNormalizedGiniCoefficientResultName].Value).Value; }
     78      protected set { ((DoubleValue)this[TrainingNormalizedGiniCoefficientResultName].Value).Value = value; }
     79    }
     80    public double TestNormalizedGiniCoefficientForDiscriminantValues {
     81      get { return ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value; }
     82      protected set { ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value = value; }
     83    }
    7384    #endregion
    7485
     
    8596      Add(new Result(TrainingRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    8697      Add(new Result(TestRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     98      Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the training partition.", new DoubleValue()));
     99      Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the test partition.", new DoubleValue()));
    87100      RegisterEventHandler();
    88101    }
     
    90103    [StorableHook(HookType.AfterDeserialization)]
    91104    private void AfterDeserialization() {
     105      #region backwards compatibility
     106      if (!ContainsKey(TrainingNormalizedGiniCoefficientResultName)) {
     107        Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the training partition.", new DoubleValue()));
     108        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the test partition.", new DoubleValue()));
     109        double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
     110        double[] originalTrainingValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToArray();
     111        double[] estimatedTestValues = EstimatedTestValues.ToArray(); // cache values
     112        double[] originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices).ToArray();
     113        double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out var errorState);
     114        if (errorState != OnlineCalculatorError.None) trainingNormalizedGini = double.NaN;
     115        double testNormalizedGini = NormalizedGiniCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
     116        if (errorState != OnlineCalculatorError.None) testNormalizedGini = double.NaN;
     117
     118        TrainingNormalizedGiniCoefficientForDiscriminantValues = trainingNormalizedGini;
     119        TestNormalizedGiniCoefficientForDiscriminantValues = testNormalizedGini;
     120      }
     121      #endregion
    92122      RegisterEventHandler();
    93123    }
     
    106136
    107137      double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    108       TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN;
     138      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR * trainingR : double.NaN;
    109139      double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    110       TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN;
     140      TestRSquared = errorState == OnlineCalculatorError.None ? testR * testR : double.NaN;
    111141
    112142      double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
     
    115145      if (errorState != OnlineCalculatorError.None) testNormalizedGini = double.NaN;
    116146
    117       TrainingNormalizedGiniCoefficient = trainingNormalizedGini;
    118       TestNormalizedGiniCoefficient = testNormalizedGini;
     147      TrainingNormalizedGiniCoefficientForDiscriminantValues = trainingNormalizedGini;
     148      TestNormalizedGiniCoefficientForDiscriminantValues = testNormalizedGini;
    119149    }
    120150
Note: See TracChangeset for help on using the changeset viewer.