-
-
Save douglaspsteen/18c49e3897eb0423c9c803dc89131324 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
# 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