#221·pyod

knn metric cosine ValueError: Unrecognized metric 'cosine'

Author: dreamflasherCreated Aug 19, 2020Updated Sep 18, 2026
Labelsbughelp wanted
clf = KNN(metric="cosine")
clf.fit(train_data)

results in

sklearn/neighbors/_binary_tree.pxi in sklearn.neighbors._ball_tree.BinaryTree.__init__()

sklearn/neighbors/_dist_metrics.pyx in sklearn.neighbors._dist_metrics.DistanceMetric.get_metric()

ValueError: Unrecognized metric 'cosine'

Also brute and kd_tree don't support cosine, meaning that cosine is not supported by any algorithm.