Search code examples
parametersh2ogbm

H2o GBM monotone_constraint parameter for R


I'm trying to use the new monotone_constraint feature in H2o GBM for R. There doesn't seem to be any examples, and I don't understand what the documentation provided means when it says

"A mapping representing monotonic constraints. Use +1 to enforce an increasing constraint and -1 to specify a decreasing constraint."

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

The error i get is For input string: "list("var1""


Solution

  • There is an example in Python (which you can read through and understand even if you prefer R), that is linked in to the docs. The "mapping" means that you specify which features you want to enforce your monotonicity constraint on, for example:

    in python you'd use a dictionary for the mapping: monotone_constraints = {"MedInc": 1, "AveOccup": -1, "HouseAge": 1} where the keys correspond to column names.

    in R you'd use monotone_constraints=list('C1'=-1, 'C2'=1) where "C1" and "C2" would be the name of your columns.

    If you're interested in understanding how the monotonicity constraints are applied see the blog that the docs provide a link to as well.