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

S3 Method predict._elnet seems to take priority over predict.model_fit and registered predict modules for glmnet based models #1252

Open
chillerb opened this issue Feb 11, 2025 · 2 comments

Comments

@chillerb
Copy link

The problem

When registering a custom model which also returns a modified glmnet class object, it took me a while to notice that parsnip also exports the S3 Method predict._elnet. Since _elnet is the first listed class object in the list of class attributes, the method predict._elnet exported by parsnip seems to take priority over parsnip's own predict.model_fit, therefore never actually calling my registered predict module, but parsnips glmnet routine. I know that this must be some super rare edge case, but it just took me an hour to figure this out and it seems like a developer pitfall to be aware of.

class(my_model)
[1] "_elnet"    "model_fit"
@EmilHvitfeldt
Copy link
Member

Hello @chillerb 👋

May I ask what specifically you want to do with the glmnet object that you can't do right now?

@chillerb
Copy link
Author

Hi @EmilHvitfeldt
The glmnet object is returned by the fit-module of my custom parsnip model (which does some tricks with input scaling before passing the data down to glmnet). So after fitting the model, I called predict on it, expecting parsnip to call my registered predict module (which again does some rescaling). However, parsnip's predict._elnet took priority instead. Sure, there are some simple work arounds for that, like wrapping the glmnet object in a list, so that the parsnip model would not have the _elnet class. It was just unexpected, that parsnip disregarded the registered fit module in that specific case.

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

2 participants