We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 023fb50 commit 5e3b845Copy full SHA for 5e3b845
Algorithms/MachineLearning/KNearestNeighbors.cs
@@ -98,9 +98,9 @@ public TLabel Predict(double[] features)
98
// Majority vote
99
var labelCounts = distances
100
.GroupBy(x => x.Label)
101
- .Select(g => new { Label = g.Key, Count = g.Count() })
+ .Select(g => new { Label = g.Key, Count = g.Count(), MinDistance = g.Min(item => item.Distance) })
102
.OrderByDescending(x => x.Count)
103
- .ThenBy(x => x.Label?.GetHashCode() ?? 0)
+ .ThenBy(x => x.MinDistance)
104
.ToList();
105
106
return labelCounts.First().Label;
0 commit comments