tidymodels / tidymodels/embed

`step_collapse_cart()` gives uninformative results when using `outcome` wrongly

Open
#228 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
R
Stars
146
Forks
23
PR merge metrics
No merged PRs in 30d

Description

library(embed)
library(modeldata)

# no outcome - bad error
recipe(Street ~., data = ames) |>
  step_collapse_cart(Neighborhood) |>
  prep() 
#> Error in `step_collapse_cart()`:
#> Caused by error in `purrr::map2()`:
#> ℹ In index: 1.
#> ℹ With name: Neighborhood.
#> Caused by error in `training[[y_name]]`:
#> ! Can't extract column with `y_name`.
#> ✖ Subscript `y_name` must be size 1, not 0.

# multiple outcomes - bad error
recipe(Street ~., data = ames) |>
  step_collapse_cart(Neighborhood, outcome = vars(MS_SubClass, MS_Zoning)) |>
  prep() 
#> Error in `step_collapse_cart()`:
#> Caused by error in `purrr::map2()`:
#> ℹ In index: 1.
#> ℹ With name: Neighborhood.
#> Caused by error in `training[[y_name]]`:
#> ! Can't extract column with `y_name`.
#> ✖ Subscript `y_name` must be size 1, not 2.

# factor outcome - disregarded
recipe(Street ~., data = ames) |>
  step_collapse_cart(Neighborhood, outcome = vars(Street)) |>
  prep() 
#> 
#> ── Recipe ──────────────────────────────────────────────────────────────────────
#> 
#> ── Inputs
#> Number of variables by role
#> outcome:    1
#> predictor: 73
#> 
#> ── Training information
#> Training data contained 2930 data points and no incomplete rows.
#> 
#> ── Operations
#> • Collapsing factor levels using CART: <none> | Trained

# numeric outcome - expected
recipe(Street ~., data = ames) |>
  step_collapse_cart(Neighborhood, outcome = vars(Sale_Price)) |>
  prep() 
#> 
#> ── Recipe ──────────────────────────────────────────────────────────────────────
#> 
#> ── Inputs
#> Number of variables by role
#> outcome:    1
#> predictor: 73
#> 
#> ── Training information
#> Training data contained 2930 data points and no incomplete rows.
#> 
#> ── Operations
#> • Collapsing factor levels using CART: Neighborhood | Trained

Created on 2024-09-11 with reprex v2.1.1

Contributor guide

Open the contributing guide

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 by reproducing the four step_collapse_cart() examples from the issue, covering no outcome, multiple outcomes, a factor outcome, and a numeric outcome. Read the implementation and existing tests for step_collapse_cart() to identify where outcome validation occurs. Done means invalid outcome usage produces an informative result while the numeric-outcome example retains its current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.