Changeset 17931 for trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
- Timestamp:
- 04/09/21 19:41:33 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
r17180 r17931 42 42 private const string NearestNeighbourClassificationModelResultName = "Nearest neighbour classification solution"; 43 43 private const string WeightsParameterName = "Weights"; 44 private const string SelfMatchParameterName = "SelfMatch";45 44 46 45 #region parameter properties 47 46 public IFixedValueParameter<IntValue> KParameter { 48 47 get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; } 49 }50 public IFixedValueParameter<BoolValue> SelfMatchParameter {51 get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; }52 48 } 53 49 public IValueParameter<DoubleArray> WeightsParameter { … … 56 52 #endregion 57 53 #region properties 58 public bool SelfMatch {59 get { return SelfMatchParameter.Value.Value; }60 set { SelfMatchParameter.Value.Value = value; }61 }62 54 public int K { 63 55 get { return KParameter.Value.Value; } … … 80 72 public NearestNeighbourClassification() 81 73 : base() { 82 Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false)));83 74 Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3))); 84 75 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)")); … … 91 82 if (!Parameters.ContainsKey(WeightsParameterName)) { 92 83 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)));96 84 } 97 85 #endregion … … 106 94 double[] weights = null; 107 95 if (Weights != null) weights = Weights.CloneAsArray(); 108 var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, SelfMatch,weights);96 var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, weights); 109 97 Results.Add(new Result(NearestNeighbourClassificationModelResultName, "The nearest neighbour classification solution.", solution)); 110 98 } 111 99 112 public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k, bool selfMatch = false,double[] weights = null) {100 public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k, double[] weights = null) { 113 101 var problemDataClone = (IClassificationProblemData)problemData.Clone(); 114 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, selfMatch,weights), problemDataClone);102 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, weights), problemDataClone); 115 103 } 116 104 117 public static INearestNeighbourModel Train(IClassificationProblemData problemData, int k, bool selfMatch = false,double[] weights = null) {105 public static INearestNeighbourModel Train(IClassificationProblemData problemData, int k, double[] weights = null) { 118 106 return new NearestNeighbourModel(problemData.Dataset, 119 107 problemData.TrainingIndices, 120 108 k, 121 selfMatch,122 109 problemData.TargetVariable, 123 110 problemData.AllowedInputVariables,
Note: See TracChangeset
for help on using the changeset viewer.