- Timestamp:
- 07/03/16 19:56:55 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
r13985 r13986 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Random; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis { … … 37 38 public enum ReplacementMethodEnum { 38 39 Median, 39 Average 40 Average, 41 Shuffle, 42 Noise 40 43 } 41 44 … … 138 141 var originalValues = dataset.GetReadOnlyDoubleValues(variable).ToList(); 139 142 double replacementValue; 143 List<double> replacementValues; 144 IRandom rand; 140 145 141 146 switch (replacement) { 142 147 case ReplacementMethodEnum.Median: 143 148 replacementValue = rows.Select(r => originalValues[r]).Median(); 149 replacementValues = Enumerable.Repeat(replacementValue, dataset.Rows).ToList(); 144 150 break; 145 151 case ReplacementMethodEnum.Average: 146 152 replacementValue = rows.Select(r => originalValues[r]).Average(); 153 replacementValues = Enumerable.Repeat(replacementValue, dataset.Rows).ToList(); 147 154 break; 155 case ReplacementMethodEnum.Shuffle: 156 // new var has same empirical distribution but the relation to y is broken 157 rand = new FastRandom(31415); 158 replacementValues = rows.Select(r => originalValues[r]).Shuffle(rand).ToList(); 159 break; 160 case ReplacementMethodEnum.Noise: 161 var avg = rows.Select(r => originalValues[r]).Average(); 162 var stdDev = rows.Select(r => originalValues[r]).StandardDeviation(); 163 rand = new FastRandom(31415); 164 replacementValues = rows.Select(_ => NormalDistributedRandom.NextDouble(rand, avg, stdDev)).ToList(); 165 break; 166 148 167 default: 149 168 throw new ArgumentException(string.Format("ReplacementMethod {0} cannot be handled.", replacement)); 150 169 } 151 170 152 dataset.ReplaceVariable(variable, Enumerable.Repeat(replacementValue, dataset.Rows).ToList());171 dataset.ReplaceVariable(variable, replacementValues); 153 172 //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements 154 173 var estimates = model.GetEstimatedValues(dataset, rows).ToList();
Note: See TracChangeset
for help on using the changeset viewer.