Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/18 10:55:23 (6 years ago)
Author:
fholzing
Message:

#2904: Removed ElementAt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r16036 r16041  
    110110      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
    111111      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);
    124115    }
    125116
     
    133124      //Calculate original quality-values (via calculator, default is R²)
    134125      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);
    138128      if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
    139129
     
    143133      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
    144134
     135
    145136      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        }
    147142      }
    148143
Note: See TracChangeset for help on using the changeset viewer.