Skip to content

parsnip should raise an error when users use logistic_reg() for multiclass classification #545

Closed
@zenggyu

Description

@zenggyu

Currently parsnip does not throw an error if a user chooses logistic_reg() to fit a multiclass classification model, but the result is wrong and misleading. Moreover, the documentation doesn't mention that logistic_reg() should only be used for binary classification. It took me a while to figure out that I should use multinom_reg() instead. It would be nice if parsnip can prevent this usage explicitly.

library(parsnip)
fit <- logistic_reg() %>%
  set_mode("classification") %>%
  set_engine("glm") %>%
  fit(Species ~ ., data = iris)
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
predict(fit, new_data = iris)
#> # A tibble: 150 x 1
#>    .pred_class
#>    <fct>      
#>  1 setosa     
#>  2 setosa     
#>  3 setosa     
#>  4 setosa     
#>  5 setosa     
#>  6 setosa     
#>  7 setosa     
#>  8 setosa     
#>  9 setosa     
#> 10 setosa     
#> # … with 140 more rows

Created on 2021-08-23 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions