tidymodels / hardhat

Construct Modeling Packages
https://hardhat.tidymodels.org
Other
103 stars 17 forks source link

add 3 `spruce_*_multi` functions #224

Closed cregouby closed 1 year ago

cregouby commented 1 year ago

Fix #161 But need clarification from #223

Examples

> spruce_numeric_multi(tibble(a = 1:5, b = 2:6))
# A tibble: 5 × 2
  .pred_1 .pred_2
    <int>   <int>
1       1       2
2       2       3
3       3       4
4       4       5
5       5       6
> spruce_class_multi(
+     tibble(a = factor(letters[1:5]), b = factor(letters[2:6]))
+ )
# A tibble: 5 × 2
  .pred_class_1 .pred_class_2
  <fct>         <fct>        
1 a             b            
2 b             c            
3 c             d            
4 d             e            
5 e             f  
library(tibble)
library(hardhat)
pred_levels_df <- tibble(day = letters[1:5],
                         month = letters[2:6])
prob_matrix_df <- tibble(day = tibble(matrix(seq(.1, .5, .1), nrow = 2, ncol = 5, byrow = T ), .name_repair = "minimal"),
                         month = tibble(matrix(seq(.6, 1, .1), nrow = 2, ncol = 5, byrow = T), .name_repair = "minimal"))
spruced <- spruce_prob_multi(pred_levels_df, prob_matrix_df)

names(spruced)
#> [1] ".pred_class_1" ".pred_class_2"

spruced$.pred_class_1
#> # A tibble: 2 × 5
#>   .pred_a .pred_b .pred_c .pred_d .pred_e
#>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1     0.1     0.2     0.3     0.4     0.5
#> 2     0.1     0.2     0.3     0.4     0.5
spruced$.pred_class_2
#> # A tibble: 2 × 5
#>   .pred_b .pred_c .pred_d .pred_e .pred_f
#>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1     0.6     0.7     0.8     0.9       1
#> 2     0.6     0.7     0.8     0.9       1

Created on 2023-03-19 by the reprex package (v2.0.1)

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.