英文:
How to pass lambda hypterparameter to Sagemaker XGboost estimator with set_hyperparameters
问题
xgb = sagemaker.estimator.Estimator(**training_dict, sagemaker_session=sagemaker_session)
xgb.set_hyperparameters(
num_round = 2000,
objective = 'binary:logistic',
tree_method = 'hist',
eval_metric = 'auc',
.
.
.
alpha = 1
)
xgb.fit({'train': s3_input_train, 'validation': s3_input_validation})
英文:
xgb = sagemaker.estimator.Estimator(**training_dict, sagemaker_session=sagemaker_session)
xgb.set_hyperparameters( num_round = 2000,
objective = 'binary:logistic',
tree_method = 'hist',
eval_metric = 'auc',
.
.
.
lambda = 0.5,
alpha = 1
)
xgb.fit({'train': s3_input_train, 'validation': s3_input_validation})
The documentation here lists lambda
for L2 Regularization but when I pass this to the set_parameter
method for sagemaker estimator I get a syntax error because lambda is keyword.
https://docs.aws.amazon.com/sagemaker/latest/dg/xgboost_hyperparameters.html
lambda = 0.5,
^
SyntaxError: invalid syntax
答案1
得分: 1
"lambda
" 是 Python 中的一个保留关键字,用于 lambda 表达式。
要解决这个问题,您可以将函数参数放入字典中,然后将字典“解包”为函数参数:
xgb.set_hyperparameters(**{ "num_round": 2000,
.
.
.
"lambda": 0.5,
"alpha": 1
})
英文:
lambda
is a reserved keyword in Python for lambda expressions.
The way you can get around it is to rather put your function arguments in a dict and then "unpack" the dict into function arguments:
xgb.set_hyperparameters(**{ "num_round": 2000,
.
.
.
"lambda": 0.5,
"alpha": 1
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论