Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5273 for trunk/sources


Ignore:
Timestamp:
01/11/11 13:59:55 (14 years ago)
Author:
gkronber
Message:

Added calculation of R², MSE and rel. Error for training best classification solution. Fixed calculation of accuracy. Fixed namespace and name of TrainingBestSymbolicClassificationSolutionAnalyzer. #1369

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Symbolic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Symbolic/Analyzer/TrainingBestSymbolicClassificationSolutionAnalyzer.cs

    r5271 r5273  
    3434using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3535using HeuristicLab.Problems.DataAnalysis.Classification;
    36 
    37 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
     36using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
     37using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
     38
     39namespace HeuristicLab.Problems.DataAnalysis.Classification.Symbolic.Analyzers {
    3840  /// <summary>
    39   /// An operator that analyzes the training best scaled symbolic regression solution.
     41  /// An operator that analyzes the training best scaled symbolic classification solution.
    4042  /// </summary>
    41   [Item("TrainingBestScaledSymbolicRegressionSolutionAnalyzer", "An operator that analyzes the training best scaled symbolic regression solution.")]
     43  [Item("TrainingBestSymbolicClassificationSolutionAnalyzer", "An operator that analyzes the training best scaled symbolic classification solution.")]
    4244  [StorableClass]
    43   public sealed class TrainingBestSymbolicClassificationSolutionAnalyzer : SingleSuccessorOperator, ISymbolicRegressionAnalyzer {
     45  public sealed class TrainingBestSymbolicClassificationSolutionAnalyzer : SingleSuccessorOperator, ISymbolicClassificationAnalyzer {
    4446    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4547    private const string QualityParameterName = "Quality";
     
    5658    private const string BestSolutionHeightParameterName = "Best training solution height";
    5759    private const string BestSolutionVariablesParameterName = "Best training solution variables";
     60    private const string BestSolutionTrainingRSquaredParameterName = "Best training solution R² (training)";
     61    private const string BestSolutionTestRSquaredParameterName = "Best training solution R² (test)";
     62    private const string BestSolutionTrainingMseParameterName = "Best training solution mean squared error (training)";
     63    private const string BestSolutionTestMseParameterName = "Best training solution mean squared error (test)";
     64    private const string BestSolutionTrainingRelativeErrorParameterName = "Best training solution relative error (training)";
     65    private const string BestSolutionTestRelativeErrorParameterName = "Best training solution relative error (test)";
    5866    private const string BestSolutionAccuracyTrainingParameterName = "Best training solution accuracy (training)";
    5967    private const string BestSolutionAccuracyTestParameterName = "Best training solution accuracy (test)";
     
    103111    public ILookupParameter<IntValue> BestSolutionVariablesParameter {
    104112      get { return (ILookupParameter<IntValue>)Parameters[BestSolutionVariablesParameterName]; }
     113    }
     114    public ILookupParameter<DoubleValue> BestSolutionTrainingRSquaredParameter {
     115      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingRSquaredParameterName]; }
     116    }
     117    public ILookupParameter<DoubleValue> BestSolutionTestRSquaredParameter {
     118      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestRSquaredParameterName]; }
     119    }
     120    public ILookupParameter<DoubleValue> BestSolutionTrainingMseParameter {
     121      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingMseParameterName]; }
     122    }
     123    public ILookupParameter<DoubleValue> BestSolutionTestMseParameter {
     124      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestMseParameterName]; }
     125    }
     126    public ILookupParameter<DoubleValue> BestSolutionTrainingRelativeErrorParameter {
     127      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingRelativeErrorParameterName]; }
     128    }
     129    public ILookupParameter<DoubleValue> BestSolutionTestRelativeErrorParameter {
     130      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestRelativeErrorParameterName]; }
    105131    }
    106132    public ILookupParameter<DoubleValue> BestSolutionTrainingAccuracyParameter {
     
    166192      get { return BestSolutionVariablesParameter.ActualValue; }
    167193      set { BestSolutionVariablesParameter.ActualValue = value; }
     194    }
     195    public DoubleValue BestSolutionTrainingRSquared {
     196      get { return BestSolutionTrainingRSquaredParameter.ActualValue; }
     197      set { BestSolutionTrainingRSquaredParameter.ActualValue = value; }
     198    }
     199    public DoubleValue BestSolutionTestRSquared {
     200      get { return BestSolutionTestRSquaredParameter.ActualValue; }
     201      set { BestSolutionTestRSquaredParameter.ActualValue = value; }
     202    }
     203    public DoubleValue BestSolutionTrainingMse {
     204      get { return BestSolutionTrainingMseParameter.ActualValue; }
     205      set { BestSolutionTrainingMseParameter.ActualValue = value; }
     206    }
     207    public DoubleValue BestSolutionTestMse {
     208      get { return BestSolutionTestMseParameter.ActualValue; }
     209      set { BestSolutionTestMseParameter.ActualValue = value; }
     210    }
     211    public DoubleValue BestSolutionTrainingRelativeError {
     212      get { return BestSolutionTrainingRelativeErrorParameter.ActualValue; }
     213      set { BestSolutionTrainingRelativeErrorParameter.ActualValue = value; }
     214    }
     215    public DoubleValue BestSolutionTestRelativeError {
     216      get { return BestSolutionTestRelativeErrorParameter.ActualValue; }
     217      set { BestSolutionTestRelativeErrorParameter.ActualValue = value; }
    168218    }
    169219    public DoubleValue BestSolutionTrainingAccuracy {
     
    196246      Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic classfication solution."));
    197247      Parameters.Add(new LookupParameter<IntValue>(BestSolutionVariablesParameterName, "The number of variables used by the best symbolic classification solution."));
     248      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingRSquaredParameterName, "The R² value on the training set of the best symbolic classification solution."));
     249      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestRSquaredParameterName, "The R² value on the test set of the best symbolic classification solution."));
     250      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingMseParameterName, "The mean squared error on the training set of the best symbolic classification solution."));
     251      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestMseParameterName, "The mean squared error value on the test set of the best symbolic classification solution."));
     252      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingRelativeErrorParameterName, "The relative error on the training set of the best symbolic classification solution."));
     253      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestRelativeErrorParameterName, "The relative error value on the test set of the best symbolic classification solution."));
    198254      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionAccuracyTrainingParameterName, "The accuracy on the training set of the best symbolic classification  solution."));
    199255      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionAccuracyTestParameterName, "The accuracy on the test set of the best symbolic classification  solution."));
    200       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored."));
     256      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic classification solution should be stored."));
    201257    }
    202258
     
    272328          IEnumerable<double> testValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable.Value, ProblemData.TestIndizes);
    273329          OnlineAccuracyEvaluator accuracyEvaluator = new OnlineAccuracyEvaluator();
     330          OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();
     331          OnlineMeanAbsolutePercentageErrorEvaluator relErrorEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator();
     332          OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator();
    274333
    275334          #region training
    276335          var originalEnumerator = trainingValues.GetEnumerator();
    277           var estimatedEnumerator = solution.EstimatedTrainingValues.GetEnumerator();
     336          var estimatedEnumerator = solution.EstimatedTrainingClassValues.GetEnumerator();
    278337          while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    279338            accuracyEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     339            mseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     340            r2Evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     341            relErrorEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
    280342          }
    281343          double trainingAccuracy = accuracyEvaluator.Accuracy;
     344          double trainingR2 = r2Evaluator.RSquared;
     345          double trainingMse = mseEvaluator.MeanSquaredError;
     346          double trainingRelError = relErrorEvaluator.MeanAbsolutePercentageError;
    282347          #endregion
    283348
    284349          accuracyEvaluator.Reset();
     350          mseEvaluator.Reset();
     351          relErrorEvaluator.Reset();
     352          r2Evaluator.Reset();
    285353
    286354          #region test
    287355          originalEnumerator = testValues.GetEnumerator();
    288           estimatedEnumerator = solution.EstimatedTestValues.GetEnumerator();
     356          estimatedEnumerator = solution.EstimatedTestClassValues.GetEnumerator();
    289357          while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    290358            accuracyEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     359            mseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     360            r2Evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     361            relErrorEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
    291362          }
    292363          double testAccuracy = accuracyEvaluator.Accuracy;
     364          double testR2 = r2Evaluator.RSquared;
     365          double testMse = mseEvaluator.MeanSquaredError;
     366          double testRelError = relErrorEvaluator.MeanAbsolutePercentageError;
    293367          #endregion
    294368          BestSolutionTrainingAccuracy = new DoubleValue(trainingAccuracy);
    295369          BestSolutionTestAccuracy = new DoubleValue(testAccuracy);
     370          BestSolutionTrainingRSquared = new DoubleValue(trainingR2);
     371          BestSolutionTestRSquared = new DoubleValue(testR2);
     372          BestSolutionTrainingMse = new DoubleValue(trainingMse);
     373          BestSolutionTestMse = new DoubleValue(testMse);
     374          BestSolutionTrainingRelativeError = new DoubleValue(trainingRelError);
     375          BestSolutionTestRelativeError = new DoubleValue(testRelError);
    296376
    297377          if (!Results.ContainsKey(BestSolutionAccuracyTrainingParameterName)) {
     378            Results.Add(new Result(BestSolutionTrainingRSquaredParameterName, BestSolutionTrainingRSquared));
     379            Results.Add(new Result(BestSolutionTestRSquaredParameterName, BestSolutionTestRSquared));
     380            Results.Add(new Result(BestSolutionTrainingMseParameterName, BestSolutionTrainingMse));
     381            Results.Add(new Result(BestSolutionTestMseParameterName, BestSolutionTestMse));
     382            Results.Add(new Result(BestSolutionTrainingRelativeErrorParameterName, BestSolutionTrainingRelativeError));
     383            Results.Add(new Result(BestSolutionTestRelativeErrorParameterName, BestSolutionTestRelativeError));
    298384            Results.Add(new Result(BestSolutionAccuracyTrainingParameterName, BestSolutionTrainingAccuracy));
    299385            Results.Add(new Result(BestSolutionAccuracyTestParameterName, BestSolutionTestAccuracy));
    300386          } else {
     387            Results[BestSolutionTrainingRSquaredParameterName].Value = BestSolutionTrainingRSquared;
     388            Results[BestSolutionTestRSquaredParameterName].Value = BestSolutionTestRSquared;
     389            Results[BestSolutionTrainingMseParameterName].Value = BestSolutionTrainingMse;
     390            Results[BestSolutionTestMseParameterName].Value = BestSolutionTestMse;
     391            Results[BestSolutionTrainingRelativeErrorParameterName].Value = BestSolutionTrainingRelativeError;
     392            Results[BestSolutionTestRelativeErrorParameterName].Value = BestSolutionTestRelativeError;
    301393            Results[BestSolutionAccuracyTrainingParameterName].Value = BestSolutionTrainingAccuracy;
    302394            Results[BestSolutionAccuracyTestParameterName].Value = BestSolutionTestAccuracy;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Symbolic/SymbolicClassificationProblem.cs

    r5271 r5273  
    3737using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3838using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
     39using HeuristicLab.Problems.DataAnalysis.Classification.Symbolic.Analyzers;
    3940
    4041namespace HeuristicLab.Problems.DataAnalysis.Classification {
Note: See TracChangeset for help on using the changeset viewer.