Why is cross_val_predict so much slower than fit for KNeighborsClassifier?

前端 未结 2 1275
醉话见心
醉话见心 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!

提交回复
热议问题