【发布时间】:2019-12-17 01:34:18
【问题描述】:
我用管道创建了GridsearchCV,我想提取管道组件 (MLPRegressor) 的一个属性 (n_iter_) 以获得最佳模型。
我正在使用 Python 3.0。
管道的创建
pipeline_steps = [('scaler', StandardScaler()), ('MLPR', MLPRegressor(solver='lbfgs', early_stopping=True, validation_fraction=0.1, max_iter=10000))]
MLPR_parameters = {'MLPR__hidden_layer_sizes':[(50,), (100,), (50,50)], 'MLPR__alpha':[0.001, 10, 1000]}
MLPR_pipeline = Pipeline(pipeline_steps)
gridCV_MLPR = GridSearchCV(MLPR_pipeline, MLPR_parameters, cv=kfold)
gridCV_MLPR.fit(X_train, y_train)
当我想用gridCV_GBR.best_params_ 提取最佳模型时,我只有 GridsearchCV 的结果:
{'MLPR__alpha': 0.001, 'MLPR__hidden_layer_sizes': (50,)}
但我想知道gridCV_MLPR的最佳模型使用的MLPRegressor的迭代次数。
如何通过带有 GridsearhCV 的管道使用为MLPRegressor() 设计的n_iter_ 属性?
【问题讨论】:
-
gridCV_MLPR.best_estimator_.n_iter_呢? -
使用这段代码,我有 'Pipeline' 对象没有属性 'n_iter_'。这很正常,因为 .n_iter_ 是 MLPregressor() 的一个属性。它包含在管道中(最好的管道,由 GridsearchCV 定义)。
标签: python scikit-learn pipeline gridsearchcv mlp