tidymodels / parsnip

A tidy unified interface to models
https://parsnip.tidymodels.org
Other
564 stars 78 forks source link

Report event level for `logistic_reg()` #1112

Open hfrick opened 2 months ago

hfrick commented 2 months ago

It's not always immediately clear which factor level is treated as the event level for logistic regression: it can vary from engine to engine or even for a single engine, depending on the input (e.g. glm() and #491). Usually, we get questions about this once it's time to calculate metrics. Hence the questions surfacing on the yardstick repo more than here and us putting info about theevent_level argument up there.

An additional way to make this a little easier to understand could be to try to store the event level in the parsnip model and, e.g., print it. That only helps when people interact with the model directly but it could be something.

Idea by @mine-cetinkaya-rundel

library(parsnip)
data(two_class_dat, package = "modeldata")

logistic_reg() %>%
  set_engine("glm") %>%
  fit(Class ~ ., data = two_class_dat)
#> parsnip model object
#> 
#> 
#> Call:  stats::glm(formula = Class ~ ., family = stats::binomial, data = data)
#> 
#> Coefficients:
#> (Intercept)            A            B  
#>      -3.749       -1.233        3.829  
#> 
#> Degrees of Freedom: 790 Total (i.e. Null);  788 Residual
#> Null Deviance:       1088 
#> Residual Deviance: 673.9     AIC: 679.9

Created on 2024-04-11 with reprex v2.1.0