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
)

Arguments

.data

dataframe, training data for tidy_xgboost

formula

formula used for tidy_xgboost

decreasing

character vector or tidyselect regular expression to designate decreasing cols

increasing

character vector or tidyselect regular expression to designate increasing cols

Value

a named integer vector with entries of 0, 1, -1

Examples




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