Skip to content

Move arg registration for bag_tree()'s rpart engine to parsnip from baguette #1398

Description

@hfrick

This originally surfaced in censored but basically: baguette registers the model args for bag_tree() with the rpart engine.

https://github.com/tidymodels/baguette/blob/237f2e6df0d8fdc24eed430db4abf3a88fe81f4d/R/bag_tree_data.R#L17-L50

censored also registered that model/engine combo, just for a different mode. So the arguments are only tunable for censored regression if we also load baguette, like we've encountered in extratests:

https://github.com/tidymodels/extratests/blob/307268a1aa4974a3a89248abbcf7d61adfac96c9/tests/testthat/test-censored-case-weights.R#L15-L16

So because both extension package register the same engine, just with a different mode, the shared part of that registration (i.e. things that are not mode-specific) should go into parsnip.


The bag_tree() rpart engine for censored regression registers no model
arguments, so none of bag_tree()'s main args (cost_complexity,
tree_depth, min_n, class_cost) are tunable. extract_parameter_set_dials()
and tunable() both come back empty, which means a bagged survival tree cannot
be tuned at all. Every other tree-based censored engine surfaces at least its
tree-control main args, so this looks like a gap rather than a deliberate
choice.

Reproducible example

library(censored)
#> Loading required package: parsnip
#> Loading required package: survival

# All of bag_tree()'s main args, set to tune(), for the rpart engine
spec <- bag_tree(
  cost_complexity = tune(),
  tree_depth = tune(),
  min_n = tune()
) |>
  set_engine("rpart") |>
  set_mode("censored regression")

# No tuning parameters are surfaced
hardhat::extract_parameter_set_dials(spec)
#> Collection of 0 parameters for tuning
#> 
#> [1] identifier type       object    
#> <0 rows> (or 0-length row.names)
#> 

# tunable() confirms the rpart engine registers none
generics::tunable(spec)
#> # A tibble: 0 × 5
#> # ℹ 5 variables: name <chr>, call_info <list>, source <chr>, component <chr>,
#> #   component_id <chr>

Expected behaviour

The tree-control main args that ipred::bagging() passes through to the
underlying rpart fit (cost_complexitycp, tree_depthmaxdepth,
min_nminsplit) should be registered via set_model_arg() in
R/bag_tree-data.R so they are tunable, mirroring decision_tree() with rpart.

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