parsnip (version 0.1.1)

set_new_model: Tools to Register Models

Description

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.

Usage

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)

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, ...)

Arguments

model

A single character string for the model type (e.g. "rand_forest", etc).

mode

A single character string for the model mode (e.g. "regression").

eng

A single character string for the model engine.

parsnip

A single character string for the "harmonized" argument name that parsnip exposes.

original

A single character string for the argument name that underlying model function uses.

func

A named character vector that describes how to call a function. func should have elements pkg and 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 predict method.

has_submodel

A single logical for whether the argument can make predictions on multiple submodels at once.

pkg

An options character string for a package name.

value

A list that conforms to the fit_obj or pred_obj description below, depending on context.

type

A single character value for the type of prediction. Possible values are: class, conf_int, numeric, pred_int, prob, quantile, and raw.

pre, post

Optional functions for pre- and post-processing of prediction results.

...

Optional arguments that should be passed into the args slot for prediction objects.

arg

A single character string for the model argument name.

fit_obj

A list with elements interface, protect, func and defaults. See the package vignette "Making a parsnip model from scratch".

pred_obj

A list with elements pre, post, func, and args. See the package vignette "Making a parsnip model from scratch".

Details

These functions are available for users to add their own models or engines (in package or otherwise) so that they can be accessed using parsnip. This are more thoroughly documented on the package web site (see references below).

In short, 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 format.

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.

References

"Making a parsnip model from scratch" https://tidymodels.github.io/parsnip/articles/articles/Scratch.html

Examples

Run this code
# NOT RUN {
# set_new_model("shallow_learning_model")

# Show the information about a model:
show_model_info("rand_forest")
# }

Run the code above in your browser using DataLab