Skip to content

error on predict(type = "prob") with outcome level named "class" #723

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

Merged
merged 3 commits into from
May 13, 2022

Conversation

simonpcouch
Copy link
Contributor

Closes #720.

One thing I'd appreciate an eye for from folks who have a better sense for model_spec objects than I do: do spec$lvl and spec$preproc$y_var always exist for relevant cases here? Do we need to unit test this more thoroughly with other model specs?

library(parsnip)
library(tibble)

x <- tibble(
  boop = factor(sample(c("class", "class_1"), 100, replace = TRUE)),
  bop = rnorm(100),
  beep = rnorm(100)
)

mod <- logistic_reg() %>%
  set_mode(mode = "classification") %>%
  fit(boop ~ bop + beep, data = x)

predict(mod, type = "prob", new_data = x)
#> Error:
#> ! The outcome variable `boop` has a level called 'class'. This level is reserved for parsnip's classification internals; please adjust the levels to use a different value.

Created on 2022-05-11 by the reprex package (v2.0.1)

@simonpcouch simonpcouch requested a review from juliasilge May 11, 2022 18:15
Copy link
Member

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that object$lvl is one of the required bits that gets returned in a model_fit. You can check that out more here.

@juliasilge
Copy link
Member

Looks great! 🚀 Apologies for being so back-and-forth on the error message.

@simonpcouch
Copy link
Contributor Author

No worries at all—thanks for the review!

@simonpcouch simonpcouch merged commit 9c2bdbb into main May 13, 2022
@simonpcouch simonpcouch deleted the predict-class-error branch May 13, 2022 17:22
@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

predict(type = "prob") should error if outcome level is named "class"
2 participants