Changeset 16041
- Timestamp:
- 08/03/18 10:55:23 (6 years ago)
- Location:
- branches/2904_CalculateImpacts
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2904_CalculateImpacts/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs
r16037 r16041 131 131 ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle, 132 132 FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) { 133 //Calculate original quality-values (via calculator, default is Accuracy) 133 //Calculate original quality-values (via calculator, default is Accuracy) 134 134 OnlineCalculatorError error; 135 135 IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); … … 144 144 145 145 foreach (var inputVariable in allowedInputVariables) { 146 impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod); 146 if (model.VariablesUsedForPrediction.Contains(inputVariable)) { 147 impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod); 148 } else { 149 impacts[inputVariable] = 0; 150 } 147 151 } 148 152 -
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 -
branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r16036 r16041 168 168 OnlineCalculatorError error; 169 169 IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 170 IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));170 IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedClassValues(rows); 171 171 var originalCalculatorValue = ClassificationSolutionVariableImpactsCalculator.CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error); 172 172 if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation."); … … 177 177 progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count); 178 178 179 double impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod); 179 double impact = 0; 180 //If the variable isn't used for prediction, it has zero impact. 181 if (model.VariablesUsedForPrediction.Contains(variableName)) { 182 impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod); 183 } 180 184 impacts.Add(new Tuple<string, double>(variableName, impact)); 181 185 } -
branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r16035 r16041 165 165 //Calculate original quality-values (via calculator, default is R²) 166 166 OnlineCalculatorError error; 167 IEnumerable<double> targetValuesPartition = rows.Select(v => problemData.TargetVariableValues.ElementAt(v)); 168 IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v)); 167 IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 168 IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedValues(rows); 169 169 170 var originalCalculatorValue = RegressionSolutionVariableImpactsCalculator.CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error); 170 171 if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation."); … … 175 176 progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count); 176 177 177 double impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod); 178 double impact = 0; 179 //If the variable isn't used for prediction, it has zero impact. 180 if (model.VariablesUsedForPrediction.Contains(variableName)) { 181 impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod); 182 } 178 183 impacts.Add(new Tuple<string, double>(variableName, impact)); 179 184 }
Note: See TracChangeset
for help on using the changeset viewer.