Ignore:
Timestamp:
08/06/18 17:35:11 (3 years ago)
Author:
fholzing
Message:

#2904: Also applied changes from regression to classification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs

    r16042 r16055  
    107107
    108108    private async void UpdateVariableImpact() {
     109      IProgress progress;
     110
    109111      //Check if the selection is valid
    110112      if (Content == null) { return; }
     
    112114      if (dataPartitionComboBox.SelectedIndex < 0) { return; }
    113115      if (factorVarReplComboBox.SelectedIndex < 0) { return; }
    114 
    115       IProgress progress;
    116116
    117117      //Prepare arguments
     
    137137
    138138        List<Tuple<string, double>> impacts = null;
    139 
    140         await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, (IClassificationModel)Content.Model.Clone(), problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
     139        await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
    141140        if (impacts == null) { return; }
    142141
    143142        rawVariableImpacts.Clear();
    144         originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(new Tuple<string, double>(v, impacts.First(vv => vv.Item1 == v).Item2)));
     143        rawVariableImpacts.AddRange(impacts);
    145144        UpdateOrdering();
    146145      }
     
    149148      }
    150149    }
    151 
    152150    private List<Tuple<string, double>> CalculateVariableImpacts(List<string> originalVariableOrdering,
    153151      IClassificationModel model,
    154152      IClassificationProblemData problemData,
    155       IEnumerable<double> estimatedValues,
     153      IEnumerable<double> estimatedClassValues,
    156154      ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum dataPartition,
    157155      ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum replMethod,
     
    166164
    167165      //Calculate original quality-values (via calculator, default is R²)
    168       OnlineCalculatorError error;
    169166      IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    170       IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedClassValues(rows);
    171       var originalCalculatorValue = ClassificationSolutionVariableImpactsCalculator.CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error);
    172       if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
    173 
     167      IEnumerable<double> estimatedClassValuesPartition = Content.GetEstimatedClassValues(rows);
     168
     169      var originalCalculatorValue = ClassificationSolutionVariableImpactsCalculator.CalculateQuality(targetValuesPartition, estimatedClassValuesPartition);
     170      var clonedModel = (IClassificationModel)model.Clone();
    174171      foreach (var variableName in originalVariableOrdering) {
    175172        if (cancellationToken.Token.IsCancellationRequested) { return null; }
     
    180177        //If the variable isn't used for prediction, it has zero impact.
    181178        if (model.VariablesUsedForPrediction.Contains(variableName)) {
    182           impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod);
     179          impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, clonedModel, problemData, modifiableDataset, rows, replMethod, factorReplMethod, targetValuesPartition, originalCalculatorValue);
    183180        }
    184181        impacts.Add(new Tuple<string, double>(variableName, impact));
Note: See TracChangeset for help on using the changeset viewer.