Magsol
Magsol

Reputation: 4690

Use other pairwise distance metrics in scikit-learn for KNN besides p-norm

For scikit-learn's KNN package, can one specify a pairwise distance metric (from the package sklearn.metrics.pairwise) that isn't the p-norm, or Minkowski distance? For example, could I use the RBF kernel? Or even the cosine distance?

Upvotes: 1

Views: 2119

Answers (1)

ogrisel
ogrisel

Reputation: 40159

Unfortunately the BallTree algorithm that is used to compute fast exact NN search on low to medium number of dimensions cannot work with arbitrary metrics.

Upvotes: 2

Related Questions