text_plain_output_1.png
from scipy.sparse import csr_matrix

from sklearn.neighbors import KNeighborsClassifier

import pandas as pd

train_data = pd.read_csv('../input/digit-recognizer/train.csv')
test_data = pd.read_csv('../input/digit-recognizer/test.csv')
train_size = round(0.8 * len(train_data))
val_size = round(0.2 * len(train_data))
train_features = train_data[:train_size]
val_features = train_data[train_size:]
train_labels = train_features.pop('label')
val_labels = val_features.pop('label')

model = KNeighborsClassifier(n_neighbors=3)
train_matrix = csr_matrix(train_features.values)
model.fit(train_matrix, train_labels.values)

print('Accuracy:')
print(model.score(val_features.values, val_labels.values))