Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs @ 10914

Last change on this file since 10914 was 10908, checked in by mleitner, 11 years ago

Add Feature correlation matrix, Add limit for distinct values in histogramm classification.

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Problems.DataAnalysis;
25using HeuristicLab.Problems.DataAnalysis.Transformations;
26
27namespace HeuristicLab.DataPreprocessing {
28  public class ProblemDataCreator {
29
30    private readonly IPreprocessingContext context;
31
32    private Dataset ExportedDataset {
33      get { return exporteDataset ?? (exporteDataset = context.Data.ExportToDataset()); }
34    }
35    private Dataset exporteDataset;
36
37    private IEnumerable<string> InputVariables { get { return context.Data.VariableNames; } }
38    private IEnumerable<ITransformation> Transformations { get { return context.Data.Transformations; } }
39
40    public ProblemDataCreator(IPreprocessingContext context) {
41      this.context = context;
42    }
43
44    public IDataAnalysisProblemData CreateProblemData() {
45      var oldProblemData = context.Problem.ProblemData;
46
47      IDataAnalysisProblemData problemData = null;
48
49      if (oldProblemData is RegressionProblemData) {
50        problemData = CreateRegressionData((RegressionProblemData)oldProblemData);
51      } else if (oldProblemData is ClassificationProblemData) {
52        problemData = CreateClassificationData((ClassificationProblemData)oldProblemData);
53      } else if (oldProblemData is ClusteringProblemData) {
54        problemData = CreateClusteringData((ClusteringProblemData)oldProblemData);
55      } else {
56        throw new NotImplementedException("The type of the DataAnalysisProblemData is not supported.");
57      }
58
59      SetTrainingAndTestPartition(problemData);
60
61      return problemData;
62    }
63
64    private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) {
65      var targetVariable = oldProblemData.TargetVariable;
66      // target variable must be double and must exist in the new dataset
67      return new RegressionProblemData(ExportedDataset, InputVariables, targetVariable, Transformations);
68    }
69
70    private IDataAnalysisProblemData CreateClassificationData(ClassificationProblemData oldProblemData) {
71      var targetVariable = oldProblemData.TargetVariable;
72      // target variable must be double and must exist in the new dataset
73      return new ClassificationProblemData(ExportedDataset, InputVariables, targetVariable, Transformations);
74    }
75
76    private IDataAnalysisProblemData CreateClusteringData(ClusteringProblemData oldProblemData) {
77      return new ClusteringProblemData(ExportedDataset, InputVariables, Transformations);
78    }
79
80    private void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData) {
81      var ppData = context.Data;
82
83      problemData.TrainingPartition.Start = ppData.TrainingPartition.Start;
84      problemData.TrainingPartition.End = ppData.TrainingPartition.End;
85      problemData.TestPartition.Start = ppData.TestPartition.Start;
86      problemData.TestPartition.End = ppData.TestPartition.End;
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.