How to pass elegantly Sklearn's GridseachCV's best parameters to another model?

后端 未结 2 1158
暖寄归人
暖寄归人 2021-02-05 14:47

I have found a set of best hyperparameters for my KNN estimator with Grid Search CV:

>>> knn_gridsearch_model.best_params_
{\'algorithm\': \'auto\', \'m         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 15:45

    I just want to point out that using the grid.best_parameters and pass them to a new model by unpacking like:

    my_model = KNeighborsClassifier(**grid.best_params_)
    

    is good and all and I personally used it a lot.
    However, as you can see in the documentation here, if your goal is to predict something using those best_parameters, you can directly use the grid.predict method which will use these best parameters for you by default.

    example:

    y_pred = grid.predict(X_test)
    

    Hope this was helpful.

提交回复
热议问题