Why testing error rate increases at high values of K in KNN algorithm?

2024/7/4 15:32:22

I am getting the error rates like this up to 20 values what might be the reason for this ?k_values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Error [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0020000000000000018, 0.0020000000000000018, 0.0020000000000000018, 0.0020000000000000018,0.0020000000000000018, 0.0020000000000000018, 0.006000000000000005, 0.0040000000000000036, 0.008000000000000007,0.006000000000000005, 0.010000000000000009, 0.008000000000000007, 0.014000000000000012, 0.01200000000000001] these are my testing error rates

I want to know the reason why the error rate increases with increase in k values?

Answer

The parameter K in KNN controls the complexity of the model. You don't give details of your specific problem, but what you likely seeing is the the bias/variance trade-off. This post is a good read about it.

Usually you try different values of the hyper parameters from the model (the value of K in the KNN) in a validation set and keep the best one. Notice that this validation set is not the same as the test set.

https://en.xdnf.cn/q/120309.html

Related Q&A

Divide and Conquer. Find the majority of element in array

I am working on a python algorithm to find the most frequent element in the list. def GetFrequency(a, element): return sum([1 for x in a if x == element])def GetMajorityElement(a):n = len(a)if n == …

Scraping dynamic webpage using Python

I am trying to scrape following dynamically generated webpage https://www.governmentjobs.com/careers/capecoral?page=1 Ive used requests, scrapy, scrapy-splash but I simply get page source code and I d…

numba cuda deprecation error : how to update my code?

Im running a jupyter notebook frome here : https://github.com/noahgift/nuclear_powered_command_line_tools/blob/master/notebooks/numba-cuda.ipynb The docs of current numba/cuda is here : https://numba.r…

reverse nested dicts using python

I already referred these posts here, here and here. I have a sample dict like as shown below t = {thisdict:{"brand": "Ford","model": "Mustang","year": …

python how to generate permutations of putting a singular character into a word

No idea how to word this so the title sucks my bad, Basically, I have a 4 letter word and I want to generate every permutation of putting a dash in it. So if my word was Cats, I want to get every permu…

Selenium Scraping Javascript Table

I am stuggling to scrape as per code below. Would apprciate it if someone can have a look at what I am missing? Regards PyProg70from selenium import webdriver from selenium.webdriver import FirefoxOp…

PYTHON REGEXP to replace recognized pattern with the pattern itself and the replacement?

Text- .1. This is just awesome.2. Google just ruined Apple.3. Apple ruined itself! pattern = (dot)(number)(dot)(singlespace)Imagine you have 30 to 40 sentences with paragraph numbers in the above patt…

How can I extract the text between a/a? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

How do I access classes and get a dir() of available actions?

I have been trying to get access to available functions for a Match Object from re.search. I am looking for a way to do that similar to how I could do dir(str) and I can find .replace.This is my dir() …

Python - IndexError: list index out of range

Why would data[entities][urls][0][expanded_url] would produce IndexError: list index out of range error? I understand what this error means but cant see why? perhaps too sleepy at 2 am? Please helpd…