如何访问管道中包含的模型中的最佳估计器参数?

2024-04-29 16:21:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下学习渠道:

Pipeline(memory=None,
     steps=[('feature_processor', DataProcessor()),
            ('classifier', GridSearchCV(cv=15,
                                        error_score='raise-deprecating',
                                        estimator=XGBClassifier(base_score=0.5,
                                                                booster='gbtree',
                                                                colsample_bylevel=1,
                                                                colsample_bynode=1, 
                                                                colsample_bytree=1,
                                                                gamma=0, learning_rate=0.1,
                                                                max_delta_step=0,..._dispatch='2*n_jobs',
                                                                refit=True,
                                                                return_train_score='warn',
                                                                scoring='accuracy', verbose=1))
            ])

里面有一个经过训练的模型,使用GridSearchCV对参数进行了优化。模型及其管道被保存到pickle中。我正在使用pickle.load()读回它,但现在我不知道如何访问GridSearchCV找到的最佳参数

有人能给我指出正确的方向吗

如果无法通过管道的信息访问此信息,是否有其他方法来执行此操作

事先非常感谢


Tags: 模型none信息参数管道pipelinestepsprocessor
2条回答

试试这个:

pipeline.named_steps['classifier'].best_params_

从您的示例中,您可以通过以下方式获得最佳模型:

loaded_pipe = pickle.load(open("<your_pkl_file>", 'rb'))
loaded_pipe['classifer'].best_estimator_

编辑:

仅适用于最佳参数:

loaded_pipe['classifer'].best_params_

相关问题 更多 >