Why is cross_val_predict so much slower than fit for KNeighborsClassifier?

前端 未结 2 1273
醉话见心
醉话见心 2021-02-10 21:16

Running locally on a Jupyter notebook and using the MNIST dataset (28k entries, 28x28 pixels per image, the following takes 27 seconds.

from sk         


        
相关标签:
2条回答
  • 2021-02-10 21:43

    KNN is also called as lazy algorithm because during fitting it does nothing but saves the input data, specifically there is no learning at all.

    During predict is the actual distance calculation happens for each test datapoint. Hence, you could understand that when using cross_val_predict, KNN has to predict on the validation data points, which makes the computation time higher!

    0 讨论(0)
  • 2021-02-10 21:44

    cross_val_predict does a fit and a predict so it might take longer than just fitting, but I did not expect 64 times longer

    0 讨论(0)
提交回复
热议问题