Skip to content

control outcome transformations #8

@topepo

Description

@topepo

The extract_* functions do different things when there is an outcome transformation in a formula:

library(tidymodels)
library(important)
tidymodels_prefer()
theme_set(theme_bw())
options(pillar.advice = FALSE, pillar.min_title_chars = Inf)
# In-line function in preprocessor formula

ames <- ames %>% select(Sale_Price, Lot_Area, Neighborhood)

lm_wflow <- workflow(log(Sale_Price) ~ . , linear_reg())
lm_fit <- fit(lm_wflow, ames)

# Different variable names and units
important:::extract_data_original(lm_fit, head(ames)) %>% 
    select(contains("Sale"))
#> # A tibble: 6 × 1
#>   Sale_Price
#>        <int>
#> 1     215000
#> 2     105000
#> 3     172000
#> 4     244000
#> 5     189900
#> 6     195500
important:::extract_data_derived(lm_fit, head(ames)) %>% 
    select(contains("Sale"))
#> # A tibble: 6 × 1
#>   `log(Sale_Price)`
#>               <dbl>
#> 1              12.3
#> 2              11.6
#> 3              12.1
#> 4              12.4
#> 5              12.2
#> 6              12.2
# In-line function in extra formula from add_model()

lm_form_wflow <- 
    workflow() %>% 
    add_formula(Sale_Price~ . ) %>% 
    add_model(linear_reg(), formula = log(Sale_Price) ~ .)

lm_form_fit <- fit(lm_form_wflow, ames)

# Same variable names and units
important:::extract_data_original(lm_form_fit, head(ames)) %>% 
    select(contains("Sale"))
#> # A tibble: 6 × 1
#>   Sale_Price
#>        <int>
#> 1     215000
#> 2     105000
#> 3     172000
#> 4     244000
#> 5     189900
#> 6     195500
important:::extract_data_derived(lm_form_fit, head(ames)) %>% 
    select(contains("Sale"))
#> # A tibble: 6 × 1
#>   Sale_Price
#>        <int>
#> 1     215000
#> 2     105000
#> 3     172000
#> 4     244000
#> 5     189900
#> 6     195500

This may be intended/helpful in some cases but definitely not in others. We should perhaps make an option for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions