Created
June 13, 2018 16:37
-
-
Save grohith327/c64745c333fda45563420af0d2960af9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.metrics import accuracy_score | |
## We take a range of values for K(1 to 20) and find the accuracy | |
## so that we can visualize how accuracy changes based on value of K | |
accuracy = [] | |
for n in range(1,21): | |
clf = KNeighborsClassifier(n_neighbors = n) | |
clf.fit(x_train,y_train) | |
y_pred = clf.predict(x_test) | |
accuracy.append(accuracy_score(y_test,y_pred)) | |
## Plotting the accuracies for different values of K | |
plt.figure(figsize=(16,9)) | |
plt.plot(range(1,21),accuracy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment