private Coord GetNearestNeighbour(Coord coord) { double minDistance = double.PositiveInfinity; Coord nearest = new Coord(250, 250, 0); foreach (Coord seenCoord in seen) { double distance = metric.GetDistance(seenCoord, coord); if (distance < minDistance && distance != 0) { minDistance = distance; nearest = seenCoord; } } return(nearest); }
public static string guesLabel(IMetric metric, int k, List <ProcessedArticle> trainingArticles, ProcessedArticle articleToLabel) { List <ProcessedArticle> knn = trainingArticles.OrderBy(a => metric.GetDistance(a.getFeatureVector(), articleToLabel.getFeatureVector())).ToList(); return(knn.Take(k).GroupBy(a => a.label).OrderBy(g => g.Count()).Last().Key); }