我有一些用于随机搜索的代码。我有一个参数“params”的字典,我想更改它以探索数据科学模型的超参数。
如果我包含 f = xgb.cv(....) 行,我的随机数不会改变循环。
_______________done_______________
{'objective': 'binary:logistic', 'booster': 'gbtree', 'eval_metric': 'logloss', 'eta': 0.03, 'subsample': 0.5488135039273248, 'colsample_bytree': 0.7151893663724195, 'max_depth': 15}
=====================================
_______________done_______________
{'objective': 'binary:logistic', 'booster': 'gbtree', 'eval_metric': 'logloss', 'eta': 0.03, 'subsample': 0.5488135039273248, 'colsample_bytree': 0.7151893663724195, 'max_depth': 15}
=====================================
_______________done_______________
{'objective': 'binary:logistic', 'booster': 'gbtree', 'eval_metric': 'logloss', 'eta': 0.03, 'subsample': 0.5488135039273248, 'colsample_bytree': 0.7151893663724195, 'max_depth': 15}
=====================================
如果我注释掉该行,它会按预期工作。我错过了一些微妙的东西。
_______________done_______________
{'objective': 'binary:logistic', 'booster': 'gbtree', 'eval_metric': 'logloss', 'eta': 0.03, 'subsample': 0.5488135039273248, 'colsample_bytree': 0.7151893663724195, 'max_depth': 15}
=====================================
_______________done_______________
{'objective': 'binary:logistic', 'booster': 'gbtree', 'eval_metric': 'logloss', 'eta': 0.03, 'subsample': 0.8579456176227568, 'colsample_bytree': 0.8472517387841254, 'max_depth': 15}
=====================================
_______________done_______________
{'objective': 'binary:logistic', 'booster': 'gbtree', 'eval_metric': 'logloss', 'eta': 0.03, 'subsample': 0.6458941130666561, 'colsample_bytree': 0.4375872112626925, 'max_depth': 3}
=====================================
我正在使用的代码(是的,我可以直接分配它们,作为故障排除的一部分,我移动了生成):
params = {
"objective": "binary:logistic",
"booster": "gbtree",
"eval_metric":"logloss",
"eta": 0.03,
"subsample": 0.5,
"colsample_bytree": 0.5,
"max_depth": 3,
}
max_depth = [3,5,10,15,20,40]
for i in range(10):
params = params
x=np.random.random()
y=np.random.random()
z=np.random.randint(0, len(max_depth))
params['subsample']=x
params['colsample_bytree']=y
params['max_depth']=max_depth[z]
f = xgb.cv(params, xgtrain, num_boost_round=5, nfold=5, stratified=False, early_stopping_rounds=5, as_pandas=True,verbose_eval=False, show_stdv=True, seed=0, shuffle=False)
print("_______________done_______________")
print(params)
print("=====================================")