Skip to content

Instantly share code, notes, and snippets.

@douglaspsteen
Created September 5, 2020 19:14
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 douglaspsteen/18c49e3897eb0423c9c803dc89131324 to your computer and use it in GitHub Desktop.
Save douglaspsteen/18c49e3897eb0423c9c803dc89131324 to your computer and use it in GitHub Desktop.
# Obtain accuracy score varying k from 1 to 99
accuracies = []
for k in range(1,100):
y_hat_test = knn_predict(X_train, X_test, y_train, y_test, k, p=1)
accuracies.append(accuracy_score(y_test, y_hat_test))
# Plot the results
fig, ax = plt.subplots(figsize=(8,6))
ax.plot(range(1,100), accuracies)
ax.set_xlabel('# of Nearest Neighbors (k)')
ax.set_ylabel('Accuracy (%)');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment