Skip to content
Advertisement

Confuse why my KNN code is throwing a ValueError

I am using sklearn for KNN regressor:

JavaScript

I get this error message:

JavaScript

Could someone please explain this? My data is in the hundred thousands for target and the thousands for input. And there is no blanks in the data.

Advertisement

Answer

Before answering the question, Let me refactor the code. You are using a dataframe so you can index single or muliple fields of the dataframe without going through the extra steps you’ve used:

JavaScript

Regarding your error, it indicates that you have some NaN, Inf, large values in your data. You can ensure these doesnt occur by filtering out the NaN and inf values using this:

JavaScript
Advertisement