I am using scikit k nearest neighbor algorithm. In KNeighborsRegressor()
function, I pass
weight = 'distance' and n_neighbors = 2
but it gives this error -
ValueError: operands could not be broadcast together with shapes (1,2,4) (1,2)
My Code:
X = [[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15],[162,137,148,159,260]]
y = [[0,1,2,3],[5,6,7,8],[44,45,46,66],[12,13,14,15]]
from sklearn.neighbors import KNeighborsRegressor
neigh = KNeighborsRegressor(n_neighbors=2,weights='distance')
neigh.fit(X, y)
print(neigh.predict([[11.5,22,13.44,15.66,66]]))
If possible, please tell me why doesn't it work. Shouldn't it just pick 2 nearest neighbors, weight them based on the distance from the query point and then predict ?