Skip to content

Double intercept when used in a workflow with a formula as preprocessor #1032

Closed
@hfrick

Description

@hfrick

Two paths through parsnip's interface matrix (formula/matrix) can produce a double intercept when used in a workflow with a formula as the preprocessor.

This is the root cause for tidymodels/censored#272 and tidymodels/workflows#210. Opening the issue here because parsnip is the place to fix this.

library(workflows)
library(parsnip)

# form_xy()
workflow() %>%
  add_formula(mpg ~ cyl + disp + hp) %>%
  add_model(linear_reg(penalty = 0.1, engine = "glmnet"), formula = mpg ~ .) %>%
  fit(data = mtcars) %>%
  extract_fit_engine() %>%
  coef() %>%
  rownames()
#> [1] "(Intercept)"   "`(Intercept)`" "cyl"           "disp"         
#> [5] "hp"

# form_form()
workflow() %>%
  add_formula(mpg ~ cyl + disp + hp) %>%
  add_model(linear_reg(engine = "lm"), formula = mpg ~ .) %>%
  fit(data = mtcars) %>%
  extract_fit_engine() %>%
  coef() %>%
  names()
#> [1] "(Intercept)"   "`(Intercept)`" "cyl"           "disp"         
#> [5] "hp"

Created on 2023-12-01 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions