ensemble: Create an ensemble model specification

Description Usage Arguments Value Examples

View source: R/ensemble.R

Description

Create an ensemble model from a list of base pipelines and a meta-model specification

Usage

1
2
ensemble(base_pipelines, meta_model, cv = partial(vfold_cv, v = 3),
  pass_predictors = FALSE)

Arguments

base_pipelines

named list of pipeline objects to use as the base models

meta_model

parsnip model specification to use as the meta learning model

cv

rsample resampling partial function. By default this is set to vfold_cv(v = 3)

pass_predictors

logical, optionally pass the predictors to the meta model as well as the predictions from the base pipeline models

Value

ensemble object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
library(tidymodels)
library(tidycrossval)
library(magrittr)

data <- iris
rec <- data %>% recipe(Species ~ .) %>%
  step_scale(all_predictors()) %>%
  step_center(all_predictors())

rf_pipeline <- pipeline(rec, rand_forest(mode = "classification") %>% set_engine("ranger"))
boost_pipeline <- pipeline(rec, boost_tree(mode = "classification") %>% set_engine("xgboost"))
base_pipelines <- list(rf = rf_pipeline, boost = boost_pipeline)
final_model <- mlp(mode = "classification") %>% set_engine("nnet")

object <- ensemble(base_pipelines, final_model, cv = . %>% vfold_cv(v = 3))
ensemble_fitted <- fit(object, data = iris)
preds <- predict(ensemble_fitted, data)

## End(Not run)

stevenpawley/tidycrossval documentation built on Oct. 3, 2019, 3:32 p.m.