model_grid: Pre-allocate an empty model grid

Description Usage Arguments Value See Also Examples

Description

Constructor function that pre-allocates an empty model grid. The model grid makes it easy to create, manage and train multiple caret models. Define the settings that by default are to be shared by all of the models in the model grid with share_settings. Add the individual specifications for the models you want to investigate with add_model. Train all of the models in the model grid with train.

The S3 method of the train function for the 'model_grid' class consolidates all model (and training) configurations from a model grid and trains them with the train function from the caret package.

Usage

1
2
3
4
model_grid()

## S3 method for class 'model_grid'
train(mg, train_all = FALSE, resample_seed = 123)

Arguments

mg

model_grid

train_all

logical if set to TRUE, all models will be trained. If set to FALSE, only models, for which no fit already exists, will be trained.

resample_seed

integer is used to create identical resamples across models in order to obtain a fair (and reproducible) comparison of the models. If set to NULL, seed will not be set (NOT advised).

Value

model_grid

model_grid equipped with fitted models.

See Also

add_model for how to add a model to a model grid, edit_model for how to edit an existing model within a model grid, share_settings for how to define the shared settings of models within a model grid, consolidate_model for how to consolidate the shared settings of a model grid and the individual settings of a given model into one complete caret model configuration and remove_model for how to remove a model from a model grid.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Pre-allocate an empty model grid.
model_grid()


library(caret)
library(magrittr)
library(dplyr)
data(GermanCredit)

# Create model grid with two different Random Forest models.
mg <-
  model_grid() %>%
  share_settings(
    y = GermanCredit[["Class"]],
    x = GermanCredit %>% select(-Class),
    metric = "ROC",
    trControl = trainControl(
      method = "cv",
      number = 2,
      summaryFunction = twoClassSummary,
      classProbs = TRUE
    )
  ) %>%
  add_model(
    model_name = "RF",
    method = "rf",
    tuneLength = 3
    ) %>%
  add_model(
    model_name = "RF NZV",
    method = "rf",
    preProc = "nzv",
    tuneGrid = data.frame(mtry = c(2, 10))
    )

# Train all model configurations in model grid.
train(mg)

modelgrid documentation built on May 2, 2019, 8:32 a.m.