Skip to contents

Augment the model spec object generated by {parsnip} with information needed to run sklearn models. See available models with rpwf_avail_models(). Importantly, also passes sklearn base learner specific arguments through the ... parameter.

Usage

set_py_engine(obj, py_module, py_base_learner, rpwf_model_tag = NULL, ...)

Arguments

obj

a model spec object generated by parsnip::set_engine() and parsnip::set_mode().

py_module

a character value that select the python module that the base learner comes from (i.e., xgboost, sklearn.ensemble, etc.).

py_base_learner

a character value that select the python base learner, (i.e., XGBClassifier, DecisionTreeClassifier, etc.).

rpwf_model_tag

a string to name this model. Useful in keeping track of different combinations of models.

...

arguments passed to the python base learner via named list. Boolean must be in R format, i.e., TRUE, FALSE.

Value

a model spec object with additional attributes self$rpwf_model_tag, self$py_base_learner and self$py_base_learner_args.

Examples

m <- parsnip::boost_tree() |>
  parsnip::set_engine("xgboost") |>
  parsnip::set_mode("classification") |>
  set_py_engine(
    "xgboost",
    "XGBClassifier",
    "my_xgboost_model",
    eval_metric = "logloss",
    use_label_encoder = FALSE,
    verbosity = 0,
    silent = TRUE,
    n_estimators = 100 # Fix the `n_estimators` at 100
  )