Changeset 16529 for branches/2520_PersistenceReintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
- Timestamp:
- 01/10/19 15:40:44 (6 years ago)
- Location:
- branches/2520_PersistenceReintegration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2520_PersistenceReintegration
- Property svn:mergeinfo changed
-
branches/2520_PersistenceReintegration/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2520_PersistenceReintegration/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/2520_PersistenceReintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
r16462 r16529 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 42 42 private const string NearestNeighbourClassificationModelResultName = "Nearest neighbour classification solution"; 43 43 private const string WeightsParameterName = "Weights"; 44 44 private const string SelfMatchParameterName = "SelfMatch"; 45 45 46 46 #region parameter properties 47 47 public IFixedValueParameter<IntValue> KParameter { 48 48 get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; } 49 } 50 public IFixedValueParameter<BoolValue> SelfMatchParameter { 51 get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; } 49 52 } 50 53 public IValueParameter<DoubleArray> WeightsParameter { … … 53 56 #endregion 54 57 #region properties 58 public bool SelfMatch { 59 get { return SelfMatchParameter.Value.Value; } 60 set { SelfMatchParameter.Value.Value = value; } 61 } 55 62 public int K { 56 63 get { return KParameter.Value.Value; } … … 73 80 public NearestNeighbourClassification() 74 81 : base() { 82 Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false))); 75 83 Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3))); 76 84 Parameters.Add(new OptionalValueParameter<DoubleArray>(WeightsParameterName, "Optional: use weights to specify individual scaling values for all features. If not set the weights are calculated automatically (each feature is scaled to unit variance)")); … … 83 91 if (!Parameters.ContainsKey(WeightsParameterName)) { 84 92 Parameters.Add(new OptionalValueParameter<DoubleArray>(WeightsParameterName, "Optional: use weights to specify individual scaling values for all features. If not set the weights are calculated automatically (each feature is scaled to unit variance)")); 93 } 94 if (!Parameters.ContainsKey(SelfMatchParameterName)) { 95 Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false))); 85 96 } 86 97 #endregion … … 95 106 double[] weights = null; 96 107 if (Weights != null) weights = Weights.CloneAsArray(); 97 var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, weights);108 var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, SelfMatch, weights); 98 109 Results.Add(new Result(NearestNeighbourClassificationModelResultName, "The nearest neighbour classification solution.", solution)); 99 110 } 100 111 101 public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k, double[] weights = null) {112 public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k, bool selfMatch = false, double[] weights = null) { 102 113 var problemDataClone = (IClassificationProblemData)problemData.Clone(); 103 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, weights), problemDataClone);114 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, selfMatch, weights), problemDataClone); 104 115 } 105 116 106 public static INearestNeighbourModel Train(IClassificationProblemData problemData, int k, double[] weights = null) {117 public static INearestNeighbourModel Train(IClassificationProblemData problemData, int k, bool selfMatch = false, double[] weights = null) { 107 118 return new NearestNeighbourModel(problemData.Dataset, 108 119 problemData.TrainingIndices, 109 120 k, 121 selfMatch, 110 122 problemData.TargetVariable, 111 123 problemData.AllowedInputVariables,
Note: See TracChangeset
for help on using the changeset viewer.