Using sklearn cross_val_score and kfolds to fit and help predict model

前端 未结 1 1194
长情又很酷
长情又很酷 2020-12-29 09:41

I\'m trying to understand using kfolds cross validation from the sklearn python module.

I understand the basic flow:

  • instantiate a model e.g. m
1条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 10:14

    No the model is not fitted. Looking at the source code for cross_val_score:

    scores=parallel(delayed(_fit_and_score)(clone(estimator),X,y,scorer,
                                            train,test,verbose,None,fit_params)
    

    As you can see, cross_val_score clones the estimator before fitting the fold training data to it. cross_val_score will give you output an array of scores which you can analyse to know how the estimator performs for different folds of the data to check if it overfits the data or not. You can know more about it here

    You need to fit the whole training data to the estimator once you are satisfied with the results of cross_val_score, before you can use it to predict on test data.

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