Skip to content

Add error for glmnet models if penalty is not exactly 1 #485

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 7 commits into from
May 11, 2021

Conversation

juliasilge
Copy link
Member

Closes #481

This PR adds a new error for glmnet models, checking if the length() of penalty is exactly one in the translate() functions. Here is what I have as the error message for now:

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
data("two_class_dat")


logistic_reg(penalty = c(0.01, 0.1)) %>% 
  set_engine("glmnet") %>% 
  fit(Class ~ ., data = two_class_dat)
#> Error: For the glmnet engine, `penalty` must be a single number.
#> * There are 2 values for `penalty`.
#> * To try multiple values for total regularization, use the tune package.


logistic_reg() %>% 
  set_engine("glmnet") %>% 
  fit(Class ~ ., data = two_class_dat)
#> Error: For the glmnet engine, `penalty` must be a single number.
#> * There are 0 values for `penalty`.
#> * To try multiple values for total regularization, use the tune package.

Created on 2021-05-06 by the reprex package (v2.0.0)

Thoughts? I have it saying to try tune even for the no-penalty case because people are probably thinking it will just go do something automatic.

@juliasilge
Copy link
Member Author

I have changed quite a lot of examples and docs now that translate() fails without a penalty for glmnet. Take a look and see if you don't like any of these choices I made.

@juliasilge juliasilge requested a review from topepo May 7, 2021 02:35
@hfrick
Copy link
Member

hfrick commented May 14, 2021

@EmilHvitfeldt pointed out that it might be little surprising to receive a message about prediction (i.e. the reference to multi_predict() when calling fit().

tidymodels/censored#55 (review)

@juliasilge
Copy link
Member Author

We chatted about this and decided we are comfortable with this message for now 👍 because we expect one of the main reasons folks might try to put multiple values for penalty in is to be able to predict at different values; we want to be sure folks know how to get those results out.

@github-actions
Copy link

github-actions bot commented Jun 2, 2021

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 Jun 2, 2021
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.

For glmnet models, fail if no penalty value is provided.
3 participants