我制作了一个带有管道的 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_.named_steps['MLPR'].n_iter_
由于 gridCV_MLPR.best_estimator_
是一个管道,我们需要使用 .named_steps['MLPR']
选择 MLPRegressor 参数。
非常感谢您非常非常快速的回答......
关于python - 使用 GridsearchCV 提取管道中最佳模型的 MLPRegressor 属性 (n_iter_ )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57427853/