Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/16 13:33:17 (8 years ago)
Author:
mkommend
Message:

#2604:

  • Base classes for data analysis, classification, and regression models
  • Added target variable to classification and regression models
  • Switched parameter order in data analysis solutions (model, problemdata)
Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour
Files:
5 edited

Legend:

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

    r13238 r13941  
    8181    public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k) {
    8282      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    83       return new NearestNeighbourClassificationSolution(problemDataClone, Train(problemDataClone, k));
     83      return new NearestNeighbourClassificationSolution(Train(problemDataClone, k), problemDataClone);
    8484    }
    8585
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassificationSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NearestNeighbourClassificationSolution(IClassificationProblemData problemData, INearestNeighbourModel nnModel)
     45    public NearestNeighbourClassificationSolution(INearestNeighbourModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("NearestNeighbourModel", "Represents a nearest neighbour model for regression and classification.")]
    36   public sealed class NearestNeighbourModel : NamedItem, INearestNeighbourModel {
     36  public sealed class NearestNeighbourModel : ClassificationModel, INearestNeighbourModel {
    3737
    3838    private alglib.nearestneighbor.kdtree kdTree;
     
    4848    }
    4949
    50     public IEnumerable<string> VariablesUsedForPrediction {
     50    public override IEnumerable<string> VariablesUsedForPrediction {
    5151      get { return allowedInputVariables; }
    5252    }
    5353
    54     public string TargetVariable {
    55       get { return targetVariable; }
    56     }
    57 
    58     [Storable]
    59     private string targetVariable;
    6054    [Storable]
    6155    private string[] allowedInputVariables;
     
    9993
    10094      k = original.k;
    101       targetVariable = original.targetVariable;
    10295      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    10396      if (original.classValues != null)
    10497        this.classValues = (double[])original.classValues.Clone();
    10598    }
    106     public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null) {
     99    public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
     100      : base(targetVariable) {
    107101      Name = ItemName;
    108102      Description = ItemDescription;
    109103      this.k = k;
    110       this.targetVariable = targetVariable;
    111104      this.allowedInputVariables = allowedInputVariables.ToArray();
    112105
     
    171164    }
    172165
    173     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     166    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    174167      if (classValues == null) throw new InvalidOperationException("No class values are defined.");
    175168      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     
    209202    }
    210203
    211     public INearestNeighbourRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    212       return new NearestNeighbourRegressionSolution(new RegressionProblemData(problemData), this);
    213     }
     204
    214205    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    215       return CreateRegressionSolution(problemData);
    216     }
    217     public INearestNeighbourClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    218       return new NearestNeighbourClassificationSolution(new ClassificationProblemData(problemData), this);
    219     }
    220     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    221       return CreateClassificationSolution(problemData);
     206      return new NearestNeighbourRegressionSolution(this, new RegressionProblemData(problemData));
     207    }
     208    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     209      return new NearestNeighbourClassificationSolution(this, new ClassificationProblemData(problemData));
    222210    }
    223211
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs

    r13238 r13941  
    8080    public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k) {
    8181      var clonedProblemData = (IRegressionProblemData)problemData.Clone();
    82       return new NearestNeighbourRegressionSolution(clonedProblemData, Train(problemData, k));
     82      return new NearestNeighbourRegressionSolution(Train(problemData, k), clonedProblemData);
    8383    }
    8484
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegressionSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NearestNeighbourRegressionSolution(IRegressionProblemData problemData, INearestNeighbourModel nnModel)
     45    public NearestNeighbourRegressionSolution(INearestNeighbourModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
Note: See TracChangeset for help on using the changeset viewer.