Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/11 16:34:31 (13 years ago)
Author:
gkronber
Message:

#1418 Implemented interactive simplifier views for symbolic classification and regression.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationEnsembleModel.cs

    r5662 r5717  
    5454      this.name = ItemName;
    5555      this.description = ItemDescription;
    56       this.models = new List<IClassificationModel>(models);
     56      this.models = new List<IClassificationModel>(models);     
    5757    }
    5858
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationSolution.cs

    r5649 r5717  
    3939    private const string TrainingAccuracyResultName = "Accuracy (training)";
    4040    private const string TestAccuracyResultName = "Accuracy (test)";
     41
     42    public new IClassificationModel Model {
     43      get { return (IClassificationModel)base.Model; }
     44      protected set { base.Model = value; }
     45    }
     46
     47    public new IClassificationProblemData ProblemData {
     48      get { return (IClassificationProblemData)base.ProblemData; }
     49      protected set { base.ProblemData = value; }
     50    }
     51
     52    public double TrainingAccuracy {
     53      get { return ((DoubleValue)this[TrainingAccuracyResultName].Value).Value; }
     54      private set { ((DoubleValue)this[TrainingAccuracyResultName].Value).Value = value; }
     55    }
     56
     57    public double TestAccuracy {
     58      get { return ((DoubleValue)this[TestAccuracyResultName].Value).Value; }
     59      private set { ((DoubleValue)this[TestAccuracyResultName].Value).Value = value; }
     60    }
     61
    4162    [StorableConstructor]
    4263    protected ClassificationSolution(bool deserializing) : base(deserializing) { }
     
    4667    public ClassificationSolution(IClassificationModel model, IClassificationProblemData problemData)
    4768      : base(model, problemData) {
     69      Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue()));
     70      Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue()));
     71      RecalculateResults();
     72    }
     73
     74    protected override void OnProblemDataChanged(EventArgs e) {
     75      base.OnProblemDataChanged(e);
     76      RecalculateResults();
     77    }
     78
     79    protected override void OnModelChanged(EventArgs e) {
     80      base.OnModelChanged(e);
     81      RecalculateResults();
     82    }
     83
     84    private void RecalculateResults() {
    4885      double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values
    4986      IEnumerable<double> originalTrainingClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     
    5491      double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues);
    5592
    56       Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue(trainingAccuracy)));
    57       Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue(testAccuracy)));
    58     }
    59 
    60     #region IClassificationSolution Members
    61 
    62     public new IClassificationModel Model {
    63       get { return (IClassificationModel)base.Model; }
    64     }
    65 
    66     public new IClassificationProblemData ProblemData {
    67       get { return (IClassificationProblemData)base.ProblemData; }
     93      TrainingAccuracy = trainingAccuracy;
     94      TestAccuracy = testAccuracy;
    6895    }
    6996
     
    89116      return Model.GetEstimatedClassValues(ProblemData.Dataset, rows);
    90117    }
    91     #endregion
    92118  }
    93119}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClusteringSolution.cs

    r5649 r5717  
    5151    public new IClusteringModel Model {
    5252      get { return (IClusteringModel)base.Model; }
     53      set { base.Model = value; }
    5354    }
    5455
    5556    public new IClusteringProblemData ProblemData {
    5657      get { return (IClusteringProblemData)base.ProblemData; }
     58      set { base.ProblemData = value; }
    5759    }
    5860
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DataAnalysisSolution.cs

    r5649 r5717  
    4848    public IDataAnalysisModel Model {
    4949      get { return (IDataAnalysisModel)this[ModelResultName].Value; }
    50       //set {
    51       //  if (this[ModelResultName].Value != value) {
    52       //    if (value != null) {
    53       //      this[ModelResultName].Value = value;
    54       //      OnModelChanged(EventArgs.Empty);
    55       //    }
    56       //  }
    57       //}
     50      protected set {
     51        if (this[ModelResultName].Value != value) {
     52          if (value != null) {
     53            this[ModelResultName].Value = value;
     54            OnModelChanged(EventArgs.Empty);
     55          }
     56        }
     57      }
    5858    }
    5959
    6060    public IDataAnalysisProblemData ProblemData {
    6161      get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
    62       //set {
    63       //  if (this[ProblemDataResultName].Value != value) {
    64       //    if (value != null) {
    65       //      ProblemData.Changed -= new EventHandler(ProblemData_Changed);
    66       //      this[ProblemDataResultName].Value = value;
    67       //      ProblemData.Changed += new EventHandler(ProblemData_Changed);
    68       //      OnProblemDataChanged(EventArgs.Empty);
    69       //    }
    70       //  }
    71       //}
     62      protected set {
     63        if (this[ProblemDataResultName].Value != value) {
     64          if (value != null) {
     65            ProblemData.Changed -= new EventHandler(ProblemData_Changed);
     66            this[ProblemDataResultName].Value = value;
     67            ProblemData.Changed += new EventHandler(ProblemData_Changed);
     68            OnProblemDataChanged(EventArgs.Empty);
     69          }
     70        }
     71      }
    7272    }
    7373    #endregion
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DiscriminantFunctionClassificationSolution.cs

    r5681 r5717  
    3838  [Item("DiscriminantFunctionClassificationSolution", "Represents a classification solution that uses a discriminant function and classification thresholds.")]
    3939  public class DiscriminantFunctionClassificationSolution : ClassificationSolution, IDiscriminantFunctionClassificationSolution {
     40    public new IDiscriminantFunctionClassificationModel Model {
     41      get { return (IDiscriminantFunctionClassificationModel)base.Model; }
     42      protected set { base.Model = value; }
     43    }
     44
    4045    [StorableConstructor]
    4146    protected DiscriminantFunctionClassificationSolution(bool deserializing) : base(deserializing) { }
     
    4853    public DiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData)
    4954      : base(model, problemData) {
    50       Model.ThresholdsChanged += new EventHandler(Model_ThresholdsChanged);
    51     }
    52 
    53     #region IDiscriminantFunctionClassificationSolution Members
    54 
    55     public new IDiscriminantFunctionClassificationModel Model {
    56       get { return (IDiscriminantFunctionClassificationModel)base.Model; }
    5755    }
    5856
     
    7270      return Model.GetEstimatedValues(ProblemData.Dataset, rows);
    7371    }
    74 
    75     public IEnumerable<double> Thresholds {
    76       get {
    77         return Model.Thresholds;
    78       }
    79       set { Model.Thresholds = new List<double>(value); }
    80     }
    81 
    82     public event EventHandler ThresholdsChanged;
    83 
    84     private void Model_ThresholdsChanged(object sender, EventArgs e) {
    85       OnThresholdsChanged(e);
    86     }
    87 
    88     protected virtual void OnThresholdsChanged(EventArgs e) {
    89       var listener = ThresholdsChanged;
    90       if (listener != null) listener(this, e);
    91     }
    92     #endregion
    9372  }
    9473}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationSolution.cs

    r5649 r5717  
    3131    IEnumerable<double> EstimatedTestClassValues { get; }
    3232    IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows);
     33
     34    double TrainingAccuracy { get; }
     35    double TestAccuracy { get; }
    3336  }
    3437}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs

    r5678 r5717  
    2626    IEnumerable<double> Thresholds { get; set; }
    2727    IEnumerable<double> ClassValues { get; set; }
     28    IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows);
     29
    2830    event EventHandler ThresholdsChanged;
    29     IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows);
    3031  }
    3132}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationSolution.cs

    r5664 r5717  
    3030    IEnumerable<double> EstimatedTestValues { get; }
    3131    IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows);
    32 
    33     IEnumerable<double> Thresholds { get; set; }
    34 
    35     event EventHandler ThresholdsChanged;
    3632  }
    3733}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionSolution.cs

    r5530 r5717  
    3030    IEnumerable<double> EstimatedTestValues { get; }
    3131    IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows);
     32
     33    double TrainingMeanSquaredError { get; }
     34    double TestMeanSquaredError { get; }
     35    double TrainingRSquared { get; }
     36    double TestRSquared { get; }
    3237  }
    3338}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/RegressionSolution.cs

    r5649 r5717  
    4444    private const string TestRelativeErrorResultName = "Average relative error (test)";
    4545
     46    public new IRegressionModel Model {
     47      get { return (IRegressionModel)base.Model; }
     48      protected set { base.Model = value; }
     49    }
     50
     51    public new IRegressionProblemData ProblemData {
     52      get { return (IRegressionProblemData)base.ProblemData; }
     53      protected set { base.ProblemData = value; }
     54    }
     55
     56    public double TrainingMeanSquaredError {
     57      get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; }
     58      private set { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }
     59    }
     60
     61    public double TestMeanSquaredError {
     62      get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; }
     63      private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }
     64    }
     65
     66    public double TrainingRSquared {
     67      get { return ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value; }
     68      private set { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }
     69    }
     70
     71    public double TestRSquared {
     72      get { return ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value; }
     73      private set { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }
     74    }
     75
     76    public double TrainingRelativeError {
     77      get { return ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value; }
     78      private set { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }
     79    }
     80
     81    public double TestRelativeError {
     82      get { return ((DoubleValue)this[TestRelativeErrorResultName].Value).Value; }
     83      private set { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }
     84    }
     85
     86
    4687    [StorableConstructor]
    4788    protected RegressionSolution(bool deserializing) : base(deserializing) { }
     
    5192    public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData)
    5293      : base(model, problemData) {
     94      Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));
     95      Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));
     96      Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
     97      Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     98      Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue()));
     99      Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue()));
     100
     101      RecalculateResults();
     102    }
     103
     104    protected override void OnProblemDataChanged(EventArgs e) {
     105      base.OnProblemDataChanged(e);
     106      RecalculateResults();
     107    }
     108    protected override void OnModelChanged(EventArgs e) {
     109      base.OnModelChanged(e);
     110      RecalculateResults();
     111    }
     112
     113    private void RecalculateResults() {
    53114      double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
    54115      IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     
    63124      double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues);
    64125
    65       Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue(trainingMSE)));
    66       Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue(testMSE)));
    67       Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue(trainingR2)));
    68       Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue(testR2)));
    69       Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue(trainingRelError)));
    70       Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue(testRelError)));
    71     }
    72 
    73     protected override void OnProblemDataChanged(EventArgs e) {
    74       base.OnProblemDataChanged(e);
    75       throw new NotImplementedException(); // need to recalculate results
    76     }
    77     protected override void OnModelChanged(EventArgs e) {
    78       base.OnModelChanged(e);
    79       throw new NotImplementedException(); // need to recalculate results
    80     }
    81     #region IRegressionSolution Members
    82 
    83     public new IRegressionModel Model {
    84       get { return (IRegressionModel)base.Model; }
    85     }
    86 
    87     public new IRegressionProblemData ProblemData {
    88       get { return (IRegressionProblemData)base.ProblemData; }
     126      TrainingMeanSquaredError = trainingMSE;
     127      TestMeanSquaredError = testMSE;
     128      TrainingRSquared = trainingR2;
     129      TestRSquared = testR2;
     130      TrainingRelativeError = trainingRelError;
     131      TestRelativeError = testRelError;
    89132    }
    90133
     
    110153      return Model.GetEstimatedValues(ProblemData.Dataset, rows);
    111154    }
    112     #endregion
    113155  }
    114156}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs

    r5681 r5717  
    7676      int[,] confusionMatrix = new int[nClasses, nClasses];
    7777
    78       // one threshold is always treated as binary separation of the remaining classes
    7978      for (int i = 1; i < thresholds.Length - 1; i++) {
    8079        double lowerThreshold = thresholds[i - 1];
Note: See TracChangeset for help on using the changeset viewer.