set_new_model_celery: Tools to Register Models

View source: R/aaa_models.R

set_new_model_celeryR Documentation

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_celery(model)

check_model_doesnt_exist_celery(model)

set_model_mode_celery(model, mode)

check_model_exists_celery(model)

set_model_engine_celery(model, mode, eng)

set_dependency_celery(model, eng, pkg = "celery", mode = NULL)

get_dependency_celery(model)

set_fit_celery(model, mode, eng, value)

get_fit_celery(model)

get_encoding_celery(model)

set_encoding_celery(model, mode, eng, options)

set_model_arg_celery(model, eng, celery, original, func, has_submodel)

show_model_info_celery(model)

set_pred_celery(model, mode, eng, type, value)

get_pred_type_celery(model, type)

Arguments

model

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

mode

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

eng

A single character string for the model engine.

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.

options

A list of options for engine-specific preprocessing encodings. See Details below.

celery

A single character string for the "harmonized" argument name that celery 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.

type

A single character value for the type of prediction. Possible values are: cluster and raw.

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 celery model from scratch".

pred_obj

A list with elements pre, post, func, and args.

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.

Details

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 celery.

In short, celery 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_celery() checks the model value and ensures that the model has already been registered. check_model_doesnt_exist_celery() 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 that celery 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 be conducted. 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 cases when fit.cluster_spec() is used and the underlying model has an x/y interface.

Another option is compute_intercept; this controls whether model.matrix() should include the intercept in its formula. This affects more than the inclusion of an intercept column. With an intercept, model.matrix() computes dummy variables for all but one factor levels. Without an intercept, model.matrix() computes a full set of indicators for the first factor variable, but an incomplete set for the remainder.

Next, the option remove_intercept will remove the intercept column after model.matrix() is finished. This can be useful if the model function (e.g. lm()) automatically generates an intercept.

Finally, allow_sparse_x specifies whether the model function can natively accommodate a sparse matrix representation for predictors during fitting and tuning.

Examples

# set_new_model_celery("shallow_learning_model")

# Show the information about a model:
show_model_info_celery("k_means")

kbodwin/celery documentation built on March 26, 2022, 12:33 a.m.