from sklearn.neighbors import KNeighborsClassifier 

from sklearn.model_selection import train_test_split

from sklearn.metrics import accuracy_score
from sklearn import datasets

digits = datasets.load_digits()


X = digits.data

y = digits.target



X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)



knn = KNeighborsClassifier(n_neighbors=5)



# Fit the classifier to the training data

knn.fit(X_train, y_train)



pred = knn.predict(X_test)
print ('\nModel accuracy score: ', accuracy_score(y_test, pred))

pred = knn.predict(digits.data[500].reshape(1, -1))
print('Predicted:', pred, 'Actual:', digits.target[500])


