Reputation: 89
Just wanted to know if anyone knows what the kernel is for the KNN regression in sklearn. I want to use a Gaussian kernel but I'm not sure if the kernel in the KNN regressor is Gaussian, any help on this topic would be greatly appreciated.
Upvotes: 2
Views: 2563
Reputation: 893
I'm assuming you are talking about sklearn.neighbors.KNeighborsRegressor here.
It's a little unclear what you mean by 'kernel', but assuming you are talking about how the k neighbours are weighted:
weights='uniform'
)weights='distance'
when creating the KNR object.While a gaussian kernel is not implemented by default, KNR also has support for arbitrary functions which decide weights. You can define one like this:
def kernel(distances):
# distances is an array of size K containing distances of neighbours
weights = gaussian(distances) # Compute an array of weights however you want
return distances
and then passing this to your KNR initialising with weights=kernel
. I recommend reading the sklearn docs for more info.
Upvotes: 2