- Timestamp:
- 06/28/16 13:33:17 (8 years ago)
- 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 32 32 [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")] 33 33 [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>(); } } 42 36 43 37 [Storable] … … 53 47 : base(original, cloner) { 54 48 this.constant = original.constant; 55 this.targetVariable = original.targetVariable;56 49 } 57 50 … … 59 52 60 53 public ConstantRegressionModel(double constant, string targetVariable = "Target") 61 : base( ) {54 : base(targetVariable) { 62 55 this.name = ItemName; 63 56 this.description = ItemDescription; 64 57 this.constant = constant; 65 58 this.ReadOnly = true; // changing a constant regression model is not supported 66 this.targetVariable = targetVariable;67 59 } 68 60 69 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 70 62 return rows.Select(row => Constant); 71 63 } 72 64 73 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 74 66 return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData)); 75 67 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r13921 r13941 33 33 [StorableClass] 34 34 [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 { 37 37 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 38 38 } … … 41 41 public IEnumerable<IRegressionModel> Models { 42 42 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; }49 43 } 50 44 … … 109 103 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { } 110 104 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights) 111 : base( ) {105 : base(string.Empty) { 112 106 this.name = ItemName; 113 107 this.description = ItemDescription; 114 108 115 116 109 this.models = new List<IRegressionModel>(models); 117 110 this.modelWeights = new List<double>(modelWeights); 111 112 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 118 113 } 119 114 120 115 public void Add(IRegressionModel model) { 116 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 117 Add(model, 1.0); 122 118 } 123 119 public void Add(IRegressionModel model, double weight) { 120 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 124 122 models.Add(model); 125 123 modelWeights.Add(weight); … … 131 129 } 132 130 public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) { 131 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable; 132 133 133 this.models.AddRange(models); 134 134 modelWeights.AddRange(weights); … … 140 140 models.RemoveAt(index); 141 141 modelWeights.RemoveAt(index); 142 143 if (!models.Any()) TargetVariable = string.Empty; 142 144 OnChanged(); 143 145 } … … 148 150 modelWeights.RemoveAt(index); 149 151 } 152 153 if (!models.Any()) TargetVariable = string.Empty; 150 154 OnChanged(); 151 155 } … … 174 178 } 175 179 176 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {180 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 177 181 double weightsSum = modelWeights.Sum(); 178 182 var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows) … … 222 226 223 227 224 public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {228 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 225 229 return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData)); 226 }227 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {228 return CreateRegressionSolution(problemData);229 230 } 230 231 }
Note: See TracChangeset
for help on using the changeset viewer.