Hi, As far as I understand, the reason that any metric other than euclidean run more slowly than expected is due to lack of compile-time inlining.
The function to compute a general metric is selected via a string argument which is not known until runtime. For this reason the cython compiler can't optimize code paths for these functions, and repeated calls of these functions run more slowly. For the euclidean case, I used an explicit special case so that the calls could be in-lined at compile time. This is why euclidean is so much faster. It's not ideal, but I don't see any way around it short of creating explicit flags for every metric. Any thoughts? Jake Jake VanderPlas Senior Data Science Fellow Director of Research in Physical Sciences University of Washington eScience Institute On Thu, Jun 11, 2015 at 2:18 PM, Stefan Kupstaitis-Dunkler < stefan....@gmail.com> wrote: > Hi all! > > I am playing around with the KNeighboursClassifier class and have a > question/concern: > > When I use the default parameters the code runs smoothly in 709 ms: > %%timeit > model = KNeighborsClassifier() > model.fit(X_train, y_train) > print(model.score(X_valid, y_valid)) > > Now I don't change anything, except, e.g., the distance class used: > %%timeit > model = KNeighborsClassifier() > model.metrics = 'manhattan' > model.fit(X_train, y_train) > print(model.score(X_valid, y_valid)) > > In my understanding the Manhattan distance shouldn't be more expensive > than the euclidean distance, but the code above runs at least a few minutes > until I decide to interrupt it. (It shouldn't even take 3 or 4 times as > long, right?) > > That also happens, when I just change the p value to 1. > > Is there something I miss? > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Scikit-learn-general mailing list > Scikit-learn-general@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/scikit-learn-general > >
------------------------------------------------------------------------------
_______________________________________________ Scikit-learn-general mailing list Scikit-learn-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/scikit-learn-general