Skip to content

These methods return the fitted model, its specification, the preprocessor, the mold, the outcome names and the parameter set of the workflow that nested_final_fit() trained.

Usage

# S3 method for class 'nested_final_fit'
extract_fit_parsnip(x, ...)

# S3 method for class 'nested_final_fit'
extract_fit_engine(x, ...)

# S3 method for class 'nested_final_fit'
extract_recipe(x, ..., estimated = TRUE)

# S3 method for class 'nested_final_fit'
extract_mold(x, ...)

# S3 method for class 'nested_final_fit'
extract_preprocessor(x, ...)

# S3 method for class 'nested_final_fit'
extract_spec_parsnip(x, ...)

# S3 method for class 'nested_final_fit'
outcome_names(x, ...)

# S3 method for class 'nested_final_fit'
extract_parameter_set_dials(x, ...)

Arguments

x

A nested_final_fit from nested_final_fit().

...

Not used, and must be empty.

estimated

For extract_recipe(), whether to return the trained recipe (TRUE, the default) or the recipe as it was given.

Value

What the same call returns for the trained workflow. For extract_parameter_set_dials(), a dials parameters object, the set the tuning run stored.

Details

Each one except extract_parameter_set_dials() returns what the same call on extract_workflow()'s output returns.

extract_parameter_set_dials() reads the parameter set that tune stored for the final fit's tuning run, because the trained workflow holds no tune() placeholder. When tune built the candidates itself, as for a numeric grid or for nested_tune_sim_anneal(), it finalized any unknown range on the predictors. With a data-frame grid, the set can keep an unknown range, such as the upper bound of mtry, so finalize it before use. A fit from nested_fit_resamples() ran no tuning and gives an error.

Examples

data(mtcars)

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
  recipes::step_pca(recipes::all_predictors(), num_comp = tune::tune())
wf <- workflows::workflow(rec, parsnip::linear_reg())

set.seed(1)
folds <- nested_resamples(
  mtcars,
  outside = rsample::vfold_cv(v = 2),
  inside = rsample::vfold_cv(v = 2)
)
set.seed(2)
res <- nested_tune_grid(wf, folds, grid = data.frame(num_comp = 1:2))
set.seed(3)
final <- nested_final_fit(wf, res)
extract_fit_parsnip(final)
#> parsnip model object
#> 
#> 
#> Call:
#> stats::lm(formula = ..y ~ ., data = data)
#> 
#> Coefficients:
#> (Intercept)          PC1  
#>    30.61860      0.03842  
#> 
extract_recipe(final)
#> 
#> ── Recipe ─────────────────────────────────────────────────────────────
#> 
#> ── Inputs 
#> Number of variables by role
#> outcome:    1
#> predictor: 10
#> 
#> ── Training information 
#> Training data contained 32 data points and no incomplete rows.
#> 
#> ── Operations 
#> • PCA extraction with: cyl, disp, hp, drat, wt, qsec, ... | Trained
outcome_names(final)
#> [1] "mpg"
extract_parameter_set_dials(final)
#> Collection of 1 parameters for tuning
#> 
#>  identifier     type    object
#>    num_comp num_comp nparam[+]
#>