how to find accuracy of KNN model ?
K nearest neighbour accuracy
Split the data on train test with general ratio being 80:20, Make predictions on those 20% of data using knn algorithm with those 80% as its training data. Than calculate accuracy on those 20% of predictions made by comparing them with actual predictions provided.
Hope this cleared your doubt.
I want to know the code for checking accuracy in knn.
Assuming you are asking for classification problem you can simply use
print(np.mean(y_pred==y_test))
where y_test contains the actual truth values ( those 20% of data kept reserved with us) and y_pred contains the predicted values that you knn algorithm has predicted using the (80% of training data).
Hope this cleared your doubt.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.