Here k is the hyperparameter and for different values of k accuracy varies.
Is there any way by which we can find the appropriate value of k in KNN ?
Diabetes Classification
Hi Abhishek,
In this example, you need to explicitly put every odd value of K, upload prediction and check accuracy.
This task can be automated when we have a larger dataset, we can split the data in training/validation set.
Then use grid search putting all the possible values of K [3,5,7,9,11,13,15,17,19,21] in the parameter of grid search, it will automatically check for each value in this list and compares the output with the y_validation set, calculates the accuracy and returns the best k value having maximum accuracy.
But, in this case we have very less dataset available, so don’t want to divide this into train/validation set (that would make our training set even less) . Still you can try this method. just keep 50 values in val set and 500 in train.
Note : K values should be in range (3, 21) not beyond that.