我如何访问管道中包含的模型中的最佳估算器参数?
How can i access to the best estimator params in a model that is contained in a pipeline?
我有以下 sklearn 管道:
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
.
找到的最佳参数
有人能给我指出正确的方向吗?
如果无法通过管道的信息访问此信息,是否还有其他方法可以做到这一点?
非常感谢您
根据您的示例,您可以通过以下方式获得最佳模型:
loaded_pipe = pickle.load(open("<your_pkl_file>", 'rb'))
loaded_pipe['classifer'].best_estimator_
编辑:
只为最佳参数:
loaded_pipe['classifer'].best_params_
试试这个:
pipeline.named_steps['classifier'].best_params_
我有以下 sklearn 管道:
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
.
有人能给我指出正确的方向吗?
如果无法通过管道的信息访问此信息,是否还有其他方法可以做到这一点?
非常感谢您
根据您的示例,您可以通过以下方式获得最佳模型:
loaded_pipe = pickle.load(open("<your_pkl_file>", 'rb'))
loaded_pipe['classifer'].best_estimator_
编辑:
只为最佳参数:
loaded_pipe['classifer'].best_params_
试试这个:
pipeline.named_steps['classifier'].best_params_