tidymodels / hardhat

Construct Modeling Packages
https://hardhat.tidymodels.org
Other
101 stars 15 forks source link

Implement `spruce_*_multiple()` family #237

Closed DavisVaughan closed 1 year ago

DavisVaughan commented 1 year ago

Closes #223 Closes #224

Implementing the approach of https://github.com/tidymodels/hardhat/issues/223#issuecomment-1486735905

@topepo what do you think about this for multi-outcomes? They go along with spruce_numeric(), spruce_class(), and spruce_prob().

library(hardhat)

spruce_numeric_multiple(1:3, foo = 2:4)
#> # A tibble: 3 × 2
#>   .pred_1 .pred_foo
#>     <int>     <int>
#> 1       1         2
#> 2       2         3
#> 3       3         4

spruce_class_multiple(
  one_step = factor(c("a", "b", "c")),
  two_step = factor(c("a", "c", "c"))
)
#> # A tibble: 3 × 2
#>   .pred_class_one_step .pred_class_two_step
#>   <fct>                <fct>               
#> 1 a                    a                   
#> 2 b                    c                   
#> 3 c                    c

one_step <- matrix(c(.3, .7, .0, .1, .3, .6), nrow = 2, byrow = TRUE)
two_step <- matrix(c(.2, .7, .1, .2, .4, .4), nrow = 2, byrow = TRUE)
binary <- matrix(c(.5, .5, .4, .6), nrow = 2, byrow = TRUE)

spruce_prob_multiple(
  one_step = spruce_prob(c("a", "b", "c"), one_step),
  two_step = spruce_prob(c("a", "b", "c"), two_step),
  binary = spruce_prob(c("yes", "no"), binary)
)
#> # A tibble: 2 × 3
#>   .pred_one_step$.pred_a $.pred_b $.pred_c .pred_two_step$.pred_a $.pred_b $.pred_c .pred_binary$.pred_yes
#>                    <dbl>    <dbl>    <dbl>                  <dbl>    <dbl>    <dbl>                  <dbl>
#> 1                    0.3      0.7      0                      0.2      0.7      0.1                    0.5
#> 2                    0.1      0.3      0.6                    0.2      0.4      0.4                    0.4
#> # … with 1 more variable: .pred_binary$.pred_no <dbl>
DavisVaughan commented 1 year ago

@cregouby what do you think of this? I can't officially request a review from you but if you could take a look as well, that'd be great.

cregouby commented 1 year ago

Looks good to me !

github-actions[bot] commented 1 year ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.