-
-
Save jurand71/f834de1d267d2a59e0516d4ff59b4944 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
print("Klasyfikator implementujący metode k-najbliższych sąsiadów z biblioteki scikit-learn") | |
lix = [] | |
liy = [] | |
index=0 | |
acc=0 | |
from sklearn.neighbors import KNeighborsClassifier | |
for k in range(1, 100): | |
neigh = KNeighborsClassifier(n_neighbors=k) | |
neigh.fit(X_train, y_train) | |
# Oblicza dokładność modelu dla danych testowych | |
liy.append(neigh.score(X_test, y_test)) | |
if liy[k-1]>acc: | |
acc=liy[k-1] | |
index=k-1 | |
lix.append(k) | |
plt.plot(lix, liy) | |
plt.show() | |
print("Najwięsza dokładność uzyskana została dla k="+str(index+1)+" i wynosi "+str(acc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment