Rahul Dev
Rahul Dev

Reputation: 612

Extract best_params after running GridSearch within a pipeline

So I ran a very thorough GridSearch with 10-fold cross-val in an integrated pipeline in the following manner-

pipeline_rf = Pipeline([
('standardize', MinMaxScaler()), 
('grid_search_lr', GridSearchCV(
    RandomForestClassifier(),
    param_grid={'bootstrap': [True],
                 'max_depth': [50, 100, 150, 200],
                 'max_features': ['auto', 'sqrt'],
                 'min_samples_leaf': [1, 2, 4],
                 'min_samples_split': [2, 5, 10],
                 'n_estimators': [100, 200, 500, 1000, 1500]},
    cv=10,
    n_jobs=-1,
    scoring='roc_auc',
    verbose=2,
    refit=True
    ))
])

pipeline_rf.fit(X_train, y_train)

How should I go about extracting the best set of parameters?

Upvotes: 0

Views: 610

Answers (1)

Vivek Kumar
Vivek Kumar

Reputation: 36619

You first need to get the gridSearchCV object from the pipeline, and then call best_params_ on it. This can be done by:

pipeline_rf.named_steps['grid_search_lr'].best_params_

Upvotes: 3

Related Questions