Skip to content

Commit

Permalink
Fewer warnings (tidymodels#195)
Browse files Browse the repository at this point in the history
* pull_* -. extract_*

* back to using surv_reg until censored is on cran

* Replace pluck with `extract_fit_engine`

Co-authored-by: Julia Silge <[email protected]>
  • Loading branch information
topepo and juliasilge authored Sep 13, 2021
1 parent b79044c commit be88b90
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions 06-fitting-models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ rand_forest(trees = 1000, min_n = 5) %>%

## Use the model results

Once the model is created and fit, we can use the results in a variety of ways; we might want to plot, print, or otherwise examine the model output. Several quantities are stored in a `r pkg(parsnip)` model object, including the fitted model. This can be found in an element called `fit`, which can be returned using the `purrr::pluck()` function:
Once the model is created and fit, we can use the results in a variety of ways; we might want to plot, print, or otherwise examine the model output. Several quantities are stored in a `r pkg(parsnip)` model object, including the fitted model. This can be found in an element called `fit`, which can be returned using the `extract_fit_engine()` function:

```{r models-pluck}
lm_form_fit %>% pluck("fit")
lm_form_fit %>% extract_fit_engine()
```

Normal methods can be applied to this object, such as printing, plotting, and so on:

```{r models-pluck-coef}
lm_form_fit %>% pluck("fit") %>% vcov()
lm_form_fit %>% extract_fit_engine() %>% vcov()
```

:::rmdwarning
Expand All @@ -274,7 +274,7 @@ One issue with some existing methods in base R is that the results are stored in
```{r models-lm-param}
model_res <-
lm_form_fit %>%
pluck("fit") %>%
extract_fit_engine() %>%
summary()
# The model coefficient table is accessible via the `coef` method.
Expand Down
2 changes: 1 addition & 1 deletion 07-the-model-workflow.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ library(workflowsets)
location_models <- workflow_set(preproc = location, models = list(lm = lm_model))
location_models
location_models$info[[1]]
pull_workflow(location_models, id = "coords_lm")
extract_workflow(location_models, id = "coords_lm")
```

Workflow sets are mostly designed to work with resampling, which is discussed in Chapter \@ref(resampling). In the object above, the columns `option` and `result` must be populated with specific types of objects that result from resampling. We will demonstrate this in more detail in Chapters \@ref(compare) and \@ref(workflow-sets).
Expand Down
8 changes: 4 additions & 4 deletions 08-feature-engineering.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ The `predict()` method applies the same preprocessing that was used on the train
predict(lm_fit, ames_test %>% slice(1:3))
```

If we need the bare model object or recipe, there are `pull_*` functions that can retrieve them:
If we need the bare model object or recipe, there are `extract_*` functions that can retrieve them:

```{r workflows-pull}
# Get the recipe after it has been estimated:
lm_fit %>%
pull_workflow_prepped_recipe()
extract_recipe(estimated = TRUE)
# To tidy the model fit:
lm_fit %>%
# This returns the parsnip object:
pull_workflow_fit() %>%
extract_fit_parsnip() %>%
# Now tidy the linear model object:
tidy() %>%
slice(1:5)
Expand Down Expand Up @@ -508,7 +508,7 @@ The `tidy()` method can be called again along with the `id` identifier we specif
```{r engineering-lm-tidy-other}
estimated_recipe <-
lm_fit %>%
pull_workflow_prepped_recipe()
extract_recipe(estimated = TRUE)
tidy(estimated_recipe, id = "my_id")
```
Expand Down
10 changes: 5 additions & 5 deletions 09-judging-model-effectiveness.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ full_model_fit <-
ad_mod %>%
fit(Class ~ (Genotype + male + age)^3, , data = ad_data)
full_model_fit %>% pluck("fit")
full_model_fit %>% extract_fit_engine()
two_way_fit <-
ad_mod %>%
fit(Class ~ (Genotype + male + age)^2, data = ad_data)
three_factor_test <-
anova(
full_model_fit %>% pluck("fit"),
two_way_fit %>% pluck("fit"),
full_model_fit %>% extract_fit_engine(),
two_way_fit %>% extract_fit_engine(),
test = "LRT"
)
Expand All @@ -72,8 +72,8 @@ main_effects_fit <-
two_factor_test <-
anova(
two_way_fit %>% pluck("fit"),
main_effects_fit %>% pluck("fit"),
two_way_fit %>% extract_fit_engine(),
main_effects_fit %>% extract_fit_engine(),
test = "LRT"
)
Expand Down
4 changes: 2 additions & 2 deletions 10-resampling.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ lm_wflow <-
lm_fit <- lm_wflow %>% fit(data = ames_train)
# Select the recipe:
pull_workflow_prepped_recipe(lm_fit)
extract_recipe(lm_fit, estimated = TRUE)
```

We can save the linear model coefficients for a fitted model object from a workflow:

```{r resampling-extract-func}
get_model <- function(x) {
pull_workflow_fit(x) %>% tidy()
extract_fit_parsnip(x) %>% tidy()
}
# Test it using:
Expand Down
6 changes: 3 additions & 3 deletions 15-workflow-sets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Since there is only a single preprocessor, this function creates a set of workfl
The `wflow_id` column is automatically created but can be modified using a call to `mutate()`. The `info` column contains a tibble with some identifiers and the workflow object. The workflow can be extracted:

```{r workflow-sets-get-workflow}
normalized %>% pull_workflow(id = "normalized_KNN")
normalized %>% extract_workflow(id = "normalized_KNN")
```

The `option` column is a placeholder for any arguments to use when we evaluate the workflow. For example, to add the neural network parameter object:
Expand Down Expand Up @@ -420,13 +420,13 @@ Similar to what we have shown in previous chapters, choosing the final model and
```{r workflow-sets-finalize}
best_results <-
race_results %>%
pull_workflow_set_result("boosting") %>%
extract_workflow_set_result("boosting") %>%
select_best(metric = "rmse")
best_results
boosting_test_results <-
race_results %>%
pull_workflow("boosting") %>%
extract_workflow("boosting") %>%
finalize_workflow(best_results) %>%
last_fit(split = concrete_split)
```
Expand Down

0 comments on commit be88b90

Please sign in to comment.