- Timestamp:
- 06/28/16 13:33:17 (8 years ago)
- 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 81 81 public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k) { 82 82 var problemDataClone = (IClassificationProblemData)problemData.Clone(); 83 return new NearestNeighbourClassificationSolution( problemDataClone, Train(problemDataClone, k));83 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k), problemDataClone); 84 84 } 85 85 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassificationSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NearestNeighbourClassificationSolution(I ClassificationProblemData problemData, INearestNeighbourModel nnModel)45 public NearestNeighbourClassificationSolution(INearestNeighbourModel nnModel, IClassificationProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [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 { 37 37 38 38 private alglib.nearestneighbor.kdtree kdTree; … … 48 48 } 49 49 50 public IEnumerable<string> VariablesUsedForPrediction {50 public override IEnumerable<string> VariablesUsedForPrediction { 51 51 get { return allowedInputVariables; } 52 52 } 53 53 54 public string TargetVariable {55 get { return targetVariable; }56 }57 58 [Storable]59 private string targetVariable;60 54 [Storable] 61 55 private string[] allowedInputVariables; … … 99 93 100 94 k = original.k; 101 targetVariable = original.targetVariable;102 95 allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 103 96 if (original.classValues != null) 104 97 this.classValues = (double[])original.classValues.Clone(); 105 98 } 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) { 107 101 Name = ItemName; 108 102 Description = ItemDescription; 109 103 this.k = k; 110 this.targetVariable = targetVariable;111 104 this.allowedInputVariables = allowedInputVariables.ToArray(); 112 105 … … 171 164 } 172 165 173 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {166 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 174 167 if (classValues == null) throw new InvalidOperationException("No class values are defined."); 175 168 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); … … 209 202 } 210 203 211 public INearestNeighbourRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 212 return new NearestNeighbourRegressionSolution(new RegressionProblemData(problemData), this); 213 } 204 214 205 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)); 222 210 } 223 211 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
r13238 r13941 80 80 public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k) { 81 81 var clonedProblemData = (IRegressionProblemData)problemData.Clone(); 82 return new NearestNeighbourRegressionSolution( clonedProblemData, Train(problemData, k));82 return new NearestNeighbourRegressionSolution(Train(problemData, k), clonedProblemData); 83 83 } 84 84 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegressionSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NearestNeighbourRegressionSolution(I RegressionProblemData problemData, INearestNeighbourModel nnModel)45 public NearestNeighbourRegressionSolution(INearestNeighbourModel nnModel, IRegressionProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 }
Note: See TracChangeset
for help on using the changeset viewer.