Reputation: 1440
I have the following sklearn pipeline:
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))
])
There is a trained model inside, which parameters were optimized using GridSearchCV
. The model with its pipeline were saved into a pickle. I'm using pickle.load()
to read it back, but now i just don't know how to access the best params that were found by GridSearchCV
.
Can please someone point me in the right direction?
If it was not possible to access this information via the pipe's info, would there be any other way to do this?
Thank you very much in advance
Upvotes: 0
Views: 1211
Reputation: 4264
Try this:
pipeline.named_steps['classifier'].best_params_
Upvotes: 4
Reputation: 5696
From your example, you can get the best model by:
loaded_pipe = pickle.load(open("<your_pkl_file>", 'rb'))
loaded_pipe['classifer'].best_estimator_
Edit:
Only for best parameters:
loaded_pipe['classifer'].best_params_
Upvotes: 2