在管道中运行GridSearch后提取best_params

时间:2018-04-14 08:05:33

标签: python-3.x scikit-learn pipeline random-forest grid-search

所以我按照以下方式在集成管道中运行了一个非常彻底的GridSearch,其交叉值为10倍 -

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)

我该如何提取最佳参数集?

1 个答案:

答案 0 :(得分:3)

首先需要从管道中获取gridSearchCV对象,然后在其上调用best_params_。这可以通过以下方式完成:

pipeline_rf.named_steps['grid_search_lr'].best_params_