I'm trying to build a knn with sklearns with a custom distance function. my distance function is:
distance(X, Y, **kwargs)
When I create the knn I do this way:
knn = KNeighborsClassifier(n_neighbors=1, metric=distance, metric_params={'weights': w_aux})
and I'm updating the w_aux var in a loop, as follows:
while run:
w_aux[it] += random_value()
score = cross_val_score(knn, X_train, y_train, cv=loo.split(X_train)).mean()
# do stuff with score
But w_aux in knn is never updated. I thought that every variable in python was passed by reference and this should work.
Any idea?