I am using scikit-learn 0.18.dev0. I know exactly the same question has been asked before here. I tried the answer presented there, I am getting the following error
The proper keyword is metric
:
import numpy as np
from sklearn.neighbors import NearestNeighbors
def mydist(x, y):
return np.sum((x-y)**2)
nn = NearestNeighbors(n_neighbors=4, algorithm='ball_tree', metric=myfunc)
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
nn.fit(X)
This is also mentioned in the docstring in the development version: https://github.com/scikit-learn/scikit-learn/blob/86b1ba72771718acbd1e07fbdc5caaf65ae65440/sklearn/neighbors/unsupervised.py#L48