MCPcopy Create free account
hub / github.com/rushter/MLAlgorithms / KNNClassifier

Class KNNClassifier

mla/knn.py:55–65  ·  view source on GitHub ↗

Nearest neighbors classifier. Note: if there is a tie for the most common label among the neighbors, then the predicted label is arbitrary.

Source from the content-addressed store, hash-verified

53
54
55class KNNClassifier(KNNBase):
56 """Nearest neighbors classifier.
57
58 Note: if there is a tie for the most common label among the neighbors, then
59 the predicted label is arbitrary."""
60
61 def aggregate(self, neighbors_targets):
62 """Return the most common target label."""
63
64 most_common_label = Counter(neighbors_targets).most_common(1)[0][0]
65 return most_common_label
66
67
68class KNNRegressor(KNNBase):

Callers 1

test_knnFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_knnFunction · 0.72