Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/16 13:33:17 (8 years ago)
Author:
mkommend
Message:

#2604:

  • Base classes for data analysis, classification, and regression models
  • Added target variable to classification and regression models
  • Switched parameter order in data analysis solutions (model, problemdata)
Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r13921 r13941  
    3232  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
    3333  [Obsolete]
    34   public class ConstantRegressionModel : NamedItem, IRegressionModel, IStringConvertibleValue {
    35     public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
    36 
    37     [Storable]
    38     private readonly string targetVariable;
    39     public string TargetVariable {
    40       get { return targetVariable; }
    41     }
     34  public class ConstantRegressionModel : RegressionModel, IStringConvertibleValue {
     35    public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
    4236
    4337    [Storable]
     
    5347      : base(original, cloner) {
    5448      this.constant = original.constant;
    55       this.targetVariable = original.targetVariable;
    5649    }
    5750
     
    5952
    6053    public ConstantRegressionModel(double constant, string targetVariable = "Target")
    61       : base() {
     54      : base(targetVariable) {
    6255      this.name = ItemName;
    6356      this.description = ItemDescription;
    6457      this.constant = constant;
    6558      this.ReadOnly = true; // changing a constant regression model is not supported
    66       this.targetVariable = targetVariable;
    6759    }
    6860
    69     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     61    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    7062      return rows.Select(row => Constant);
    7163    }
    7264
    73     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     65    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    7466      return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData));
    7567    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r13921 r13941  
    3333  [StorableClass]
    3434  [Item("RegressionEnsembleModel", "A regression model that contains an ensemble of multiple regression models")]
    35   public sealed class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel {
    36     public IEnumerable<string> VariablesUsedForPrediction {
     35  public sealed class RegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel {
     36    public override IEnumerable<string> VariablesUsedForPrediction {
    3737      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
    3838    }
     
    4141    public IEnumerable<IRegressionModel> Models {
    4242      get { return new List<IRegressionModel>(models); }
    43     }
    44 
    45     [Storable]
    46     private readonly string target;
    47     public string TargetVariable {
    48       get { return models.First().TargetVariable; }
    4943    }
    5044
     
    109103    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { }
    110104    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights)
    111       : base() {
     105      : base(string.Empty) {
    112106      this.name = ItemName;
    113107      this.description = ItemDescription;
    114108
    115 
    116109      this.models = new List<IRegressionModel>(models);
    117110      this.modelWeights = new List<double>(modelWeights);
     111
     112      if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable;
    118113    }
    119114
    120115    public void Add(IRegressionModel model) {
     116      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
    121117      Add(model, 1.0);
    122118    }
    123119    public void Add(IRegressionModel model, double weight) {
     120      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
     121
    124122      models.Add(model);
    125123      modelWeights.Add(weight);
     
    131129    }
    132130    public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) {
     131      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable;
     132
    133133      this.models.AddRange(models);
    134134      modelWeights.AddRange(weights);
     
    140140      models.RemoveAt(index);
    141141      modelWeights.RemoveAt(index);
     142
     143      if (!models.Any()) TargetVariable = string.Empty;
    142144      OnChanged();
    143145    }
     
    148150        modelWeights.RemoveAt(index);
    149151      }
     152
     153      if (!models.Any()) TargetVariable = string.Empty;
    150154      OnChanged();
    151155    }
     
    174178    }
    175179
    176     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     180    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    177181      double weightsSum = modelWeights.Sum();
    178182      var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)
     
    222226
    223227
    224     public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     228    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    225229      return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData));
    226     }
    227     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    228       return CreateRegressionSolution(problemData);
    229230    }
    230231  }
Note: See TracChangeset for help on using the changeset viewer.