首页 > 解决方案 > R 的 H2o GBM monotone_constraint 参数

问题描述

我正在尝试在 H2o GBM for R 中使用新的 monotone_constraint 功能。似乎没有任何示例,而且我不明白提供的文档所说的含义是什么

“表示单调约束的映射。使用 +1 强制增加约束,使用 -1 指定减少约束。”

gbm_1 <- h2o.gbm(
model_id = "gbm_1"
,x = xvars
,y = yvar
,training_frame = train
,distribution = "bernoulli"
,monotone_constraints = list("var1",1)
)

我得到的错误是 For input string: "list("var1""

标签: parametersh2ogbm

解决方案


Python 中有一个示例(即使您更喜欢 R,也可以通读和理解),它链接到docs中。“映射”意味着您指定要强制执行单调性约束的功能,例如:

在 python 中,您将使用字典进行映射:monotone_constraints = {"MedInc": 1, "AveOccup": -1, "HouseAge": 1}其中键对应于列名。

在 R 中,您将使用monotone_constraints=list('C1'=-1, 'C2'=1)where"C1"并且"C2"将是列的名称。

如果您有兴趣了解如何应用单调性约束,请参阅文档也提供链接的博客。


推荐阅读