<jupyter_start><jupyter_text>Import Libraries<jupyter_code>from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.neighbors import KNeighborsClassifier<jupyter_output><empty_output><jupyter_text>Load and split the dataset<jupyter_code>digits=datasets.load_digits()
features = digits.data
# print (features)
labels = digits.target
# print(labels)

# split the data to 60% training and 40% testing
x_train,x_test,y_train,y_test=train_test_split(features,labels,test_size=.4)
print('Training samples is : ',len(x_train))
print('Testing samples is : ', len((x_test)))<jupyter_output>Training samples is :  1078
Testing samples is :  719<jupyter_text>When K=1<jupyter_code>knn = KNeighborsClassifier(n_neighbors=1)
clf = knn.fit(x_train,y_train)
predictions = knn.predict(x_test)
print('Training ......')
print ('Accuracy is : ',accuracy_score(y_test,predictions))<jupyter_output>Training ......
Accuracy is :  0.988873435327<jupyter_text>When K=3<jupyter_code>knn = KNeighborsClassifier(n_neighbors=3)
clf = knn.fit(x_train,y_train)
predictions = knn.predict(x_test)
print('Training ......')
print ('Accuracy is : ',accuracy_score(y_test,predictions))<jupyter_output>Training ......
Accuracy is :  0.990264255911<jupyter_text>When K=5<jupyter_code>knn = KNeighborsClassifier(n_neighbors=5)
clf = knn.fit(x_train,y_train)
predictions = knn.predict(x_test)
print('Training ......')
print ('Accuracy is : ',accuracy_score(y_test,predictions))<jupyter_output>Training ......
Accuracy is :  0.988873435327<jupyter_text>When K=7<jupyter_code>knn = KNeighborsClassifier(n_neighbors=7)
clf = knn.fit(x_train,y_train)
predictions = knn.predict(x_test)
print('Training ......')
print ('Accuracy is : ',accuracy_score(y_test,predictions))<jupyter_output>Training ......
Accuracy is :  0.988873435327<jupyter_text>When K=9<jupyter_code>knn = KNeighborsClassifier(n_neighbors=9)
clf = knn.fit(x_train,y_train)
predictions = knn.predict(x_test)
print('Training ......')
print ('Accuracy is : ',accuracy_score(y_test,predictions))<jupyter_output>Training ......
Accuracy is :  0.986091794159
{'fraction_non_alphanumeric': 0.1396103896103896, 'fraction_numerical': 0.040352504638218926, 'mean_word_length': 7.3604651162790695, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '647357', 'license': 'Apache-2.0', 'n_tokens_mistral': 920, 'n_tokens_neox': 831, 'n_words': 123, 'path': 'Data Pure/KNN/KNN.ipynb', 'repo_name': 'Aboalarbe/Recognition-of-Handwritten-Digits-Using-Machine-Learning-Techniques', 'size': '2156'}