Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

probability predictions when using tailor #251

Open
topepo opened this issue Sep 20, 2024 · 1 comment
Open

probability predictions when using tailor #251

topepo opened this issue Sep 20, 2024 · 1 comment

Comments

@topepo
Copy link
Member

topepo commented Sep 20, 2024

type = "prob" returns class predictions.

library(tidymodels)
library(tailor)

set.seed(816)
sim_data <- sim_classification(2000) %>%
  bind_cols(sim_noise(2000, 500))
sim_split <- initial_split(sim_data)
sim_tr <- training(sim_split)
sim_te <- testing(sim_split)

rf_spec <- rand_forest() %>% set_mode("classification")
rf_wflow <- workflow(class ~ ., rf_spec)

cal_post <-
  tailor() %>%
  adjust_probability_calibration(method = "beta")

rf_cal_wflow <-
  rf_wflow %>%
  add_tailor(cal_post, prop = .1)

set.seed(456)
rf_cal_fit <- fit(rf_cal_wflow, sim_tr)

# augment() not ready yet
predict(rf_cal_fit, sim_te)
#> # A tibble: 500 × 1
#>    .pred_class
#>    <fct>      
#>  1 class_2    
#>  2 class_2    
#>  3 class_2    
#>  4 class_1    
#>  5 class_1    
#>  6 class_2    
#>  7 class_1    
#>  8 class_1    
#>  9 class_2    
#> 10 class_2    
#> # ℹ 490 more rows
predict(rf_cal_fit, sim_te, type = "prob")
#> # A tibble: 500 × 1
#>    .pred_class
#>    <fct>      
#>  1 class_2    
#>  2 class_2    
#>  3 class_2    
#>  4 class_1    
#>  5 class_1    
#>  6 class_2    
#>  7 class_1    
#>  8 class_1    
#>  9 class_2    
#> 10 class_2    
#> # ℹ 490 more rows

Created on 2024-09-20 with reprex v2.1.0

@topepo
Copy link
Member Author

topepo commented Sep 20, 2024

It does appear to work when used inside of fit_resamples() though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant