I have a matrix X that I am trying to use KNN with pearson correlation metric. Is it possible to use the pearson correlation as the sklearn metric? I have tried something like this:
def pearson_calc(M):
P = (1 - np.array([[pearsonr(a,b)[0] for a in M] for b in M]))
return P
nbrs = NearestNeighbors(n_neighbors=4, metric=pearson_calc)
nbrs.fit(X)
knbrs = nbrs.kneighbors(X)
However, this does not work as I get the following error:
pearson_affinity() takes 1 positional argument but 2 were given
I am assuming that the pearson_calc function is wrong. Maybe it needs an a,b parameters and not a matrix.