helper function to create the integer vector to pass to the monotone_constraints
argument in xgboost
create_monotone_constraints(
.data,
formula,
decreasing = NULL,
increasing = NULL
)
dataframe, training data for tidy_xgboost
formula used for tidy_xgboost
character vector or tidyselect regular expression to designate decreasing cols
character vector or tidyselect regular expression to designate increasing cols
a named integer vector with entries of 0, 1, -1
iris %>%
framecleaner::create_dummies(Species) -> iris_dummy
#> 1 column(s) have become 3 dummy columns
iris_dummy %>%
tidy_formula(target= Petal.Length) -> petal_form
iris_dummy %>%
create_monotone_constraints(petal_form,
decreasing = tidyselect::matches("Petal|Species"),
increasing = "Sepal.Width")
#> Sepal.Length Sepal.Width Petal.Width species_setosa
#> 0 1 -1 -1
#> species_versicolor species_virginica
#> -1 -1