bag_mars() is a way to generate a specification of a model before fitting and allows the model to be created using different packages in R. The main arguments for the model are:

  • num_terms: The number of features that will be retained in the final model.

  • prod_degree: The highest possible degree of interaction between features. A value of 1 indicates and additive model while a value of 2 allows, but does not guarantee, two-way interactions between features.

  • prune_method: The type of pruning. Possible values are listed in ?earth.

These arguments are converted to their specific names at the time that the model is fit. Other options and argument can be set using set_engine(). If left to their defaults here (NULL), the values are taken from the underlying model functions. If parameters need to be modified, update() can be used in lieu of recreating the object from scratch.

bag_mars(
  mode = "unknown",
  num_terms = NULL,
  prod_degree = NULL,
  prune_method = NULL
)

# S3 method for bag_mars
update(
  object,
  parameters = NULL,
  num_terms = NULL,
  prod_degree = NULL,
  prune_method = NULL,
  fresh = FALSE,
  ...
)

Arguments

mode

A single character string for the type of model. Possible values for this model are "unknown", "regression", or "classification".

num_terms

The number of features that will be retained in the final model, including the intercept.

prod_degree

The highest possible interaction degree.

prune_method

The pruning method.

object

A bagged MARS model specification.

parameters

A 1-row tibble or named list with main parameters to update. If the individual arguments are used, these will supersede the values in parameters. Also, using engine arguments in this object will result in an error.

fresh

A logical for whether the arguments should be modified in-place of or replaced wholesale.

...

Not used for update().

Details

The model can be created using the fit() function using the following engines:

  • R: "earth" (the default)

Examples

library(parsnip) set.seed(7396) bag_mars(num_terms = 7) %>% set_mode("regression") %>% set_engine("earth", times = 3) %>% fit(mpg ~ ., data = mtcars)
#> parsnip model object #> #> Fit time: 834ms #> Bagged MARS (regression with 3 members) #> #> Variable importance scores include: #> #> # A tibble: 9 × 4 #> term value std.error used #> <chr> <dbl> <dbl> <int> #> 1 disp 66.7 0 2 #> 2 hp 33.3 0 1 #> 3 wt 14.8 3.85 2 #> 4 carb 12.6 0.843 2 #> 5 am 5.67 0 1 #> 6 gear 5.37 0 1 #> 7 gear-unused 2.98 0 1 #> 8 hp-unused 2.98 0 1 #> 9 qsec-unused 2.01 0 1 #>
model <- bag_mars(num_terms = 10, prune_method = "none") model
#> Bagged MARS Model Specification (unknown) #> #> Main Arguments: #> num_terms = 10 #> prune_method = none #>
update(model, num_terms = 2)
#> Bagged MARS Model Specification (unknown) #> #> Main Arguments: #> num_terms = 2 #> prune_method = none #>
update(model, num_terms = 2, fresh = TRUE)
#> Bagged MARS Model Specification (unknown) #> #> Main Arguments: #> num_terms = 2 #>