Tools to Register ModelsSource:
These functions are similar to constructors and can be used to validate that there are no conflicts with the underlying model structures used by the package.
set_new_model(model) set_model_mode(model, mode) set_model_engine(model, mode, eng) set_model_arg(model, eng, parsnip, original, func, has_submodel) set_dependency(model, eng, pkg = "parsnip", mode = NULL) get_dependency(model) set_fit(model, mode, eng, value) get_fit(model) set_pred(model, mode, eng, type, value) get_pred_type(model, type) show_model_info(model) pred_value_template(pre = NULL, post = NULL, func, ...) set_encoding(model, mode, eng, options) get_encoding(model)
A single character string for the model type (e.g.
A single character string for the model mode (e.g. "regression").
A single character string for the model engine.
A single character string for the "harmonized" argument name that
A single character string for the argument name that underlying model function uses.
A named character vector that describes how to call a function.
funcshould have elements
fun. The former is optional but is recommended and the latter is required. For example,
c(pkg = "stats", fun = "lm")would be used to invoke the usual linear regression function. In some cases, it is helpful to use
c(fun = "predict")when using a package's
A single logical for whether the argument can make predictions on multiple submodels at once.
An options character string for a package name.
A list that conforms to the
pred_objdescription below, depending on context.
A single character value for the type of prediction. Possible values are:
- pre, post
Optional functions for pre- and post-processing of prediction results.
Optional arguments that should be passed into the
argsslot for prediction objects.
A list of options for engine-specific preprocessing encodings. See Details below.
These functions are available for users to add their
own models or engines (in a package or otherwise) so that they can
be accessed using
parsnip. This is more thoroughly documented
on the package web site (see references below).
parsnip stores an environment object that contains
all of the information and code about how models are used (e.g.
fitting, predicting, etc). These functions can be used to add
models to that environment as well as helper functions that can
be used to makes sure that the model data is in the right
check_model_exists() checks the model value and ensures that the model has
already been registered.
check_model_doesnt_exist() checks the model value
and also checks to see if it is novel in the environment.
The options for engine-specific encodings dictate how the predictors should be
handled. These options ensure that the data
parsnip gives to the underlying model allows for a model fit that is
as similar as possible to what it would have produced directly.
For example, if
fit() is used to fit a model that does not have
a formula interface, typically some predictor preprocessing must
glmnet is a good example of this.
There are four options that can be used for the encodings:
predictor_indicators describes whether and how to create indicator/dummy
variables from factor predictors. There are three options:
"none" (do not
expand factor predictors),
"traditional" (apply the standard
model.matrix() encodings), and
"one_hot" (create the complete set
including the baseline level for all factors). This encoding only affects
fit.model_spec() is used and the underlying model has an x/y
Another option is
compute_intercept; this controls whether
should include the intercept in its formula. This affects more than the
inclusion of an intercept column. With an intercept,
computes dummy variables for all but one factor levels. Without an
model.matrix() computes a full set of indicators for the
first factor variable, but an incomplete set for the remainder.
allow_sparse_x specifies whether the model function can natively
accommodate a sparse matrix representation for predictors during fitting
"How to build a parsnip model" https://www.tidymodels.org/learn/develop/models/
# set_new_model("shallow_learning_model") # Show the information about a model: show_model_info("rand_forest") #> Information for `rand_forest` #> modes: unknown, classification, regression, censored regression #> #> engines: #> classification: randomForest, ranger¹, spark #> regression: randomForest, ranger¹, spark #> #> ¹The model can use case weights. #> #> arguments: #> ranger: #> mtry --> mtry #> trees --> num.trees #> min_n --> min.node.size #> randomForest: #> mtry --> mtry #> trees --> ntree #> min_n --> nodesize #> spark: #> mtry --> feature_subset_strategy #> trees --> num_trees #> min_n --> min_instances_per_node #> #> fit modules: #> engine mode #> ranger classification #> ranger regression #> randomForest classification #> randomForest regression #> spark classification #> spark regression #> #> prediction modules: #> mode engine methods #> classification randomForest class, prob, raw #> classification ranger class, conf_int, prob, raw #> classification spark class, prob #> regression randomForest numeric, raw #> regression ranger conf_int, numeric, raw #> regression spark numeric #>