gpt4 book ai didi

python - 如何让管道中的回归器解包参数?

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:15 24 4
gpt4 key购买 nike

所以我正在使用 scikit-learn 管道来减少编写重复代码的步骤。但是,我看不出如何编写代码来解压每个回归变量的参数。

在使用Pipeline之前,我写了一个类来解压参数。虽然我确实相信有更好的方法可以解决这个问题,但效果很好。

我不想一直手动写参数

from sklearn.pipeline import make_pipeline
pipe_et = make_pipeline(StandardScaler(), ExtraTreesRegressor(n_estimators = 1000, random_state = Seed))
pipe_rf = make_pipeline(StandardScaler(), XGBRegressor())

这是我要解压的参数的例子

rf_params = {'n_estimators': 1000, 'n_jobs': -1, 'warm_start': True, 'max_features':2}

没有错误。我不想做额外的劳动,但我希望 **params 可以工作,但我不知道如何进行。请帮助我改进我的编码风格

最佳答案

您可以循环遍历您的 pipe_rf 对象并获取如下参数:

for i in pipe_rf:
print (i.get_params())

输出

{'copy': True, 'with_mean': True, 'with_std': True}
{'base_score': 0.5, 'booster': 'gbtree', 'colsample_bylevel': 1, 'colsample_bynode': 1, 'colsample_bytree': 1, 'gamma': 0, 'importance_type': 'gain', 'learning_rate': 0.1, 'max_delta_step': 0, 'max_depth': 3, 'min_child_weight': 1, 'missing': None, 'n_estimators': 100, 'n_jobs': 1, 'nthread': None, 'objective': 'reg:linear', 'random_state': 0, 'reg_alpha': 0, 'reg_lambda': 1, 'scale_pos_weight': 1, 'seed': None, 'silent': None, 'subsample': 1, 'verbosity': 1}

希望这对您有所帮助!

关于python - 如何让管道中的回归器解包参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57168229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com