Changeset 16041 for branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
- Timestamp:
- 08/03/18 10:55:23 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
r16036 r16041 110 110 FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best, 111 111 DataPartitionEnum dataPartition = DataPartitionEnum.Training) { 112 return CalculateImpacts(solution.Model, solution.ProblemData, solution.EstimatedValues, replacementMethod, factorReplacementMethod, dataPartition); 113 } 114 115 public static IEnumerable<Tuple<string, double>> CalculateImpacts( 116 IRegressionModel model, 117 IRegressionProblemData problemData, 118 IEnumerable<double> estimatedValues, 119 ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle, 120 FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best, 121 DataPartitionEnum dataPartition = DataPartitionEnum.Training) { 122 IEnumerable<int> rows = GetPartitionRows(dataPartition, problemData); 123 return CalculateImpacts(model, problemData, estimatedValues, rows, replacementMethod, factorReplacementMethod); 112 IEnumerable<int> rows = (GetPartitionRows(dataPartition, solution.ProblemData)); 113 IEnumerable<double> estimatedValues = solution.GetEstimatedValues(rows); 114 return CalculateImpacts(solution.Model, solution.ProblemData, estimatedValues, rows, replacementMethod, factorReplacementMethod); 124 115 } 125 116 … … 133 124 //Calculate original quality-values (via calculator, default is R²) 134 125 OnlineCalculatorError error; 135 IEnumerable<double> targetValuesPartition = rows.Select(v => problemData.TargetVariableValues.ElementAt(v)); 136 IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v)); 137 var originalCalculatorValue = CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error); 126 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 127 var originalCalculatorValue = CalculateVariableImpact(targetValues, estimatedValues, out error); 138 128 if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation."); 139 129 … … 143 133 var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable(); 144 134 135 145 136 foreach (var inputVariable in allowedInputVariables) { 146 impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod); 137 if (model.VariablesUsedForPrediction.Contains(inputVariable)) { 138 impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValues, originalCalculatorValue, replacementMethod, factorReplacementMethod); 139 } else { 140 impacts[inputVariable] = 0; 141 } 147 142 } 148 143
Note: See TracChangeset
for help on using the changeset viewer.