使用GridsearchCV为管道中的最佳模型提取mlprepressor属性(n\u iter\u)?

2024-05-11 19:10:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我用管道做了一个GridsearchCV,我想提取管道组件(mlprepressor)的一个属性(n_iter_),以获得最佳模型。你知道吗

我正在使用python3.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的最佳模型所使用的mlprepressor的迭代次数。你知道吗

如何通过GridsearhCV的管道使用为MLPRegressor()设计的n_iter_属性?你知道吗


Tags: 模型layer属性管道pipelinestepshiddenparameters
1条回答
网友
1楼 · 发布于 2024-05-11 19:10:29

谢谢你的帮助

我找到了解决办法:

gridCV_MLPR.best_estimator_.named_steps['MLPR'].n_iter_

由于gridCV_MLPR.best_estimator_是一个管道,我们需要用.named_steps['MLPR']选择mlprepressor参数。你知道吗

非常感谢你非常,非常迅速的回答。。。你知道吗

相关问题 更多 >