- Timestamp:
- 03/16/11 16:34:31 (14 years ago)
- 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 54 54 this.name = ItemName; 55 55 this.description = ItemDescription; 56 this.models = new List<IClassificationModel>(models); 56 this.models = new List<IClassificationModel>(models); 57 57 } 58 58 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationSolution.cs
r5649 r5717 39 39 private const string TrainingAccuracyResultName = "Accuracy (training)"; 40 40 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 41 62 [StorableConstructor] 42 63 protected ClassificationSolution(bool deserializing) : base(deserializing) { } … … 46 67 public ClassificationSolution(IClassificationModel model, IClassificationProblemData problemData) 47 68 : 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() { 48 85 double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values 49 86 IEnumerable<double> originalTrainingClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes); … … 54 91 double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues); 55 92 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; 68 95 } 69 96 … … 89 116 return Model.GetEstimatedClassValues(ProblemData.Dataset, rows); 90 117 } 91 #endregion92 118 } 93 119 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClusteringSolution.cs
r5649 r5717 51 51 public new IClusteringModel Model { 52 52 get { return (IClusteringModel)base.Model; } 53 set { base.Model = value; } 53 54 } 54 55 55 56 public new IClusteringProblemData ProblemData { 56 57 get { return (IClusteringProblemData)base.ProblemData; } 58 set { base.ProblemData = value; } 57 59 } 58 60 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DataAnalysisSolution.cs
r5649 r5717 48 48 public IDataAnalysisModel Model { 49 49 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 } 58 58 } 59 59 60 60 public IDataAnalysisProblemData ProblemData { 61 61 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 } 72 72 } 73 73 #endregion -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DiscriminantFunctionClassificationSolution.cs
r5681 r5717 38 38 [Item("DiscriminantFunctionClassificationSolution", "Represents a classification solution that uses a discriminant function and classification thresholds.")] 39 39 public class DiscriminantFunctionClassificationSolution : ClassificationSolution, IDiscriminantFunctionClassificationSolution { 40 public new IDiscriminantFunctionClassificationModel Model { 41 get { return (IDiscriminantFunctionClassificationModel)base.Model; } 42 protected set { base.Model = value; } 43 } 44 40 45 [StorableConstructor] 41 46 protected DiscriminantFunctionClassificationSolution(bool deserializing) : base(deserializing) { } … … 48 53 public DiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) 49 54 : base(model, problemData) { 50 Model.ThresholdsChanged += new EventHandler(Model_ThresholdsChanged);51 }52 53 #region IDiscriminantFunctionClassificationSolution Members54 55 public new IDiscriminantFunctionClassificationModel Model {56 get { return (IDiscriminantFunctionClassificationModel)base.Model; }57 55 } 58 56 … … 72 70 return Model.GetEstimatedValues(ProblemData.Dataset, rows); 73 71 } 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 #endregion93 72 } 94 73 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationSolution.cs
r5649 r5717 31 31 IEnumerable<double> EstimatedTestClassValues { get; } 32 32 IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows); 33 34 double TrainingAccuracy { get; } 35 double TestAccuracy { get; } 33 36 } 34 37 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs
r5678 r5717 26 26 IEnumerable<double> Thresholds { get; set; } 27 27 IEnumerable<double> ClassValues { get; set; } 28 IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows); 29 28 30 event EventHandler ThresholdsChanged; 29 IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows);30 31 } 31 32 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationSolution.cs
r5664 r5717 30 30 IEnumerable<double> EstimatedTestValues { get; } 31 31 IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows); 32 33 IEnumerable<double> Thresholds { get; set; }34 35 event EventHandler ThresholdsChanged;36 32 } 37 33 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionSolution.cs
r5530 r5717 30 30 IEnumerable<double> EstimatedTestValues { get; } 31 31 IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows); 32 33 double TrainingMeanSquaredError { get; } 34 double TestMeanSquaredError { get; } 35 double TrainingRSquared { get; } 36 double TestRSquared { get; } 32 37 } 33 38 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/RegressionSolution.cs
r5649 r5717 44 44 private const string TestRelativeErrorResultName = "Average relative error (test)"; 45 45 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 46 87 [StorableConstructor] 47 88 protected RegressionSolution(bool deserializing) : base(deserializing) { } … … 51 92 public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData) 52 93 : 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() { 53 114 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values 54 115 IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes); … … 63 124 double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues); 64 125 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; 89 132 } 90 133 … … 110 153 return Model.GetEstimatedValues(ProblemData.Dataset, rows); 111 154 } 112 #endregion113 155 } 114 156 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs
r5681 r5717 76 76 int[,] confusionMatrix = new int[nClasses, nClasses]; 77 77 78 // one threshold is always treated as binary separation of the remaining classes79 78 for (int i = 1; i < thresholds.Length - 1; i++) { 80 79 double lowerThreshold = thresholds[i - 1];
Note: See TracChangeset
for help on using the changeset viewer.