tidymodels / tidymodels/important

control outcome transformations

Open
#8 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
R
Stars
19
Forks
1
Avg merge
2h 6m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the extract_data_original() and extract_data_derived() entry points and reproduce the two workflow examples in the issue. Decide how an option should control outcome transformations in each formula arrangement, then verify that the selected behavior is consistent for both workflows.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.