Skip to content

Instantly share code, notes, and snippets.

@ahmdrz
Created May 20, 2019 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmdrz/5d92ee95cf12c697e72b269c7f6f7b66 to your computer and use it in GitHub Desktop.
Save ahmdrz/5d92ee95cf12c697e72b269c7f6f7b66 to your computer and use it in GitHub Desktop.
Simple knn in sklearn
from sklearn.neighbors import KNeighborsClassifier
samples = [[0], [1], [2], [3]]
labels = [0, 0, 1, 1]
item_to_predict = [[1.1]]
model = KNeighborsClassifier(n_neighbors=3, metric='euclidean')
model.fit(samples, labels)
predict = model.predict(item_to_predict)
print(predict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment