private IEnumerable <IResult> ExtractAndAggregateClassificationSolutions(IEnumerable <KeyValuePair <string, IItem> > resultCollections) { Dictionary <string, List <IClassificationSolution> > resultSolutions = new Dictionary <string, List <IClassificationSolution> >(); foreach (var result in resultCollections) { var classificationSolution = result.Value as IClassificationSolution; if (classificationSolution != null) { if (resultSolutions.ContainsKey(result.Key)) { resultSolutions[result.Key].Add(classificationSolution); } else { resultSolutions.Add(result.Key, new List <IClassificationSolution>() { classificationSolution }); } } } var aggregatedResults = new List <IResult>(); foreach (KeyValuePair <string, List <IClassificationSolution> > solutions in resultSolutions) { // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem. var targetVariable = solutions.Value.First().ProblemData.TargetVariable; var dataset = (Dataset)Problem.ProblemData.Dataset; if (ShuffleSamples.Value) { var random = new FastRandom(seed); dataset = dataset.Shuffle(random); } var problemDataClone = new ClassificationProblemData(dataset, Problem.ProblemData.AllowedInputVariables, targetVariable); // set partitions of problem data clone correctly problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value; // clone models var ensembleSolution = new ClassificationEnsembleSolution(problemDataClone); ensembleSolution.AddClassificationSolutions(solutions.Value); aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution)); } List <IResult> flattenedResults = new List <IResult>(); CollectResultsRecursively("", aggregatedResults, flattenedResults); return(flattenedResults); }
private IEnumerable <IResult> ExtractAndAggregateClassificationSolutions(IEnumerable <KeyValuePair <string, IItem> > resultCollections) { Dictionary <string, List <IClassificationSolution> > resultSolutions = new Dictionary <string, List <IClassificationSolution> >(); foreach (var result in resultCollections) { var classificationSolution = result.Value as IClassificationSolution; if (classificationSolution != null) { if (resultSolutions.ContainsKey(result.Key)) { resultSolutions[result.Key].Add(classificationSolution); } else { resultSolutions.Add(result.Key, new List <IClassificationSolution>() { classificationSolution }); } } } var aggregatedResults = new List <IResult>(); foreach (KeyValuePair <string, List <IClassificationSolution> > solutions in resultSolutions) { // clone manually to correctly clone references between cloned root objects Cloner cloner = new Cloner(); var problemDataClone = (IClassificationProblemData)cloner.Clone(Problem.ProblemData); // set partitions of problem data clone correctly problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value; // clone models var ensembleSolution = new ClassificationEnsembleSolution(problemDataClone); ensembleSolution.AddClassificationSolutions(solutions.Value); aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution)); } List <IResult> flattenedResults = new List <IResult>(); CollectResultsRecursively("", aggregatedResults, flattenedResults); return(flattenedResults); }
public override void Execute() { IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; var solutionGroups = from pair in GetDataAnalysisResults(activeView) group pair.Value by pair.Key into g select g; foreach (var group in solutionGroups) { // check if all solutions in the group are either only regression or only classification solutions if (group.All(s => s is IRegressionSolution)) { // show all regression ensembles // N.B. this assumes all solutions are based on the same problem data! // the problem data is not cloned because the individual solutions were already cloned var problemData = group.OfType <IRegressionSolution>().First().ProblemData; var ensemble = new RegressionEnsembleSolution(problemData); ensemble.Name = group.Key + " ensemble"; var nestedSolutions = group.OfType <RegressionEnsembleSolution>().SelectMany(e => e.RegressionSolutions); var solutions = group.Where(s => !(s is RegressionEnsembleSolution)).OfType <IRegressionSolution>(); ensemble.AddRegressionSolutions(nestedSolutions.Concat(solutions)); MainFormManager.MainForm.ShowContent(ensemble); } else if (group.All(s => s is IClassificationSolution)) { // show all classification ensembles // N.B. this assumes all solutions are based on the same problem data! // the problem data is not cloned because the individual solutions were already cloned var problemData = (ClassificationProblemData)group.OfType <IClassificationSolution>().First().ProblemData; var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty <IClassificationModel>(), problemData); ensemble.Name = group.Key + " ensemble"; var nestedSolutions = group.OfType <ClassificationEnsembleSolution>().SelectMany(e => e.ClassificationSolutions); var solutions = group.Where(s => !(s is ClassificationEnsembleSolution)).OfType <IClassificationSolution>(); ensemble.AddClassificationSolutions(nestedSolutions.Concat(solutions)); MainFormManager.MainForm.ShowContent(ensemble); } } }
public override void Execute() { IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; var solutionGroups = from pair in GetDataAnalysisResults(activeView) group pair.Value by pair.Key into g select g; foreach (var group in solutionGroups) { // check if all solutions in the group are either only regression or only classification solutions if (group.All(s => s is IRegressionSolution)) { // show all regression ensembles // N.B. this assumes all solutions are based on the same problem data! // the problem data is not cloned because the individual solutions were already cloned var problemData = group.OfType<IRegressionSolution>().First().ProblemData; var ensemble = new RegressionEnsembleSolution(problemData); ensemble.Name = group.Key + " ensemble"; var nestedSolutions = group.OfType<RegressionEnsembleSolution>().SelectMany(e => e.RegressionSolutions); var solutions = group.Where(s => !(s is RegressionEnsembleSolution)).OfType<IRegressionSolution>(); ensemble.AddRegressionSolutions(nestedSolutions.Concat(solutions)); MainFormManager.MainForm.ShowContent(ensemble); } else if (group.All(s => s is IClassificationSolution)) { // show all classification ensembles // N.B. this assumes all solutions are based on the same problem data! // the problem data is not cloned because the individual solutions were already cloned var problemData = (ClassificationProblemData)group.OfType<IClassificationSolution>().First().ProblemData; var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty<IClassificationModel>(), problemData); ensemble.Name = group.Key + " ensemble"; var nestedSolutions = group.OfType<ClassificationEnsembleSolution>().SelectMany(e => e.ClassificationSolutions); var solutions = group.Where(s => !(s is ClassificationEnsembleSolution)).OfType<IClassificationSolution>(); ensemble.AddClassificationSolutions(nestedSolutions.Concat(solutions)); MainFormManager.MainForm.ShowContent(ensemble); } } }