Created
September 9, 2020 15:10
-
-
Save StephenFordham/239580eb26720fbebf0652edc27cbe4e to your computer and use it in GitHub Desktop.
error_rate
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
error_rate = [] | |
for i in range(1, 40): | |
knn = KNeighborsClassifier(n_neighbors=i) | |
knn.fit(X_train, y_train) | |
pred_i = knn.predict(X_test) | |
error_rate.append(np.mean(pred_i != y_test)) | |
plt.figure(figsize=(10, 6)) | |
plt.plot(range(1, 40), error_rate, color='blue', linestyle='--', | |
markersize=10, markerfacecolor='red', marker='o') | |
plt.title('K versus Error rate') | |
plt.xlabel('K') | |
plt.ylabel('Error rate') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment