Untitled

mail@pastecode.io avatar
unknown
python
a year ago
613 B
1
Indexable
Never
# 1) initialize a k-NN classifier with n_neighbors parameter set to best_k
knn = KNeighborsClassifier(n_neighbors = 3)

# 2) combine the training and validation sets (you may want to look up numpy.concatenate function for this)
X = np.concatenate((X_train, X_test), axis=0)
y = np.concatenate((Y_train, y_test), axis=0)
# 3) train the classifier using this set
knn.fit(X, y)
# 4) get the predictions of the classifier on the test set 
y_pred = knn.predict(X_test)
# 5) compute the accuracy of the predictions on the test set
print('Test accuracy for k=', best_k, ' :', y_pred)


# Report your result