1
$\begingroup$

Having difficulty doing something very basic: create a random dataset taking on values between -1,1, plot them, and also fit a KNN model to the data and fit it over the data. Using numpy to create the dataset.

The KNN fitted line looks like a spider web. Unsure where I went wrong in the code. K=2 in the image, but the problem is identical even if I set K = 80. enter image description here https://github.com/PortWhisperer/MachineLearningStudies/blob/master/crappy-KNN.py

$\endgroup$

1 Answer 1

0
$\begingroup$

I sorted the X array with numpy.sort() and the plot sorted itself out.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.