1. If I extend the analysis to K=100, then again, we get the minimum error at k=37 only. Why? Because there is not any statistical method to find an optimal value of K, just remember that at the end model evaluation, we get the optimal K value as the square root of N(number of sample points). This idea is not written in any book just concluded from the experiences.
  2. Setting K value equal to the number of sample points is computationally very expensive, and you will get the same optimal K value as I derived in the above answer.
  3. Whenever you increase the test size, then your model will get fewer data to train, and so on, you will get unexpected results. In the given code, we set test_size = 0.2, and we got K=37 as an optimum value, but if you change test size, then optimal K value will definitely change.

--

--

Machine Learning | Data Science Practitioner, Connect with me on LinkedIn - https://linkedin.com/in/amey23/ Twitter — https://twitter.com/AmeyBand4

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store