Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/20/11 16:10:07 (13 years ago)
Author:
gkronber
Message:

#1450: implemented support for ensemble solutions for classification.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r6184 r6239  
    376376        results.Add(result.Name, result.Value);
    377377      }
     378      foreach (IResult result in ExtractAndAggregateClassificationSolutions(resultCollections)) {
     379        results.Add(result.Name, result.Value);
     380      }
    378381      results.Add("Execution Time", new TimeSpanValue(this.ExecutionTime));
    379382      results.Add("CrossValidation Folds", new RunCollection(runs));
     
    406409    }
    407410
     411    private IEnumerable<IResult> ExtractAndAggregateClassificationSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     412      Dictionary<string, List<IClassificationSolution>> resultSolutions = new Dictionary<string, List<IClassificationSolution>>();
     413      foreach (var result in resultCollections) {
     414        var classificationSolution = result.Value as IClassificationSolution;
     415        if (classificationSolution != null) {
     416          if (resultSolutions.ContainsKey(result.Key)) {
     417            resultSolutions[result.Key].Add(classificationSolution);
     418          } else {
     419            resultSolutions.Add(result.Key, new List<IClassificationSolution>() { classificationSolution });
     420          }
     421        }
     422      }
     423      List<IResult> aggregatedResults = new List<IResult>();
     424      foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) {
     425        var problemDataClone = (IClassificationProblemData)Problem.ProblemData.Clone();
     426        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     427        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     428        var ensembleSolution = new ClassificationEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone,
     429          solutions.Value.Select(x => x.ProblemData.TrainingPartition),
     430          solutions.Value.Select(x => x.ProblemData.TestPartition));
     431
     432        aggregatedResults.Add(new Result(solutions.Key, ensembleSolution));
     433      }
     434      return aggregatedResults;
     435    }
     436
    408437    private static IEnumerable<IResult> ExtractAndAggregateResults<T>(IEnumerable<KeyValuePair<string, IItem>> results)
    409438  where T : class, IItem, new() {
Note: See TracChangeset for help on using the changeset viewer.