Skip to content

Instantly share code, notes, and snippets.

Created Sep 5, 2020
What would you like to do?
# 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