Skip to content

Make NotInitializedError a subclass of NotFittedError #859

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

Closed
timokau opened this issue May 23, 2022 · 2 comments
Closed

Make NotInitializedError a subclass of NotFittedError #859

timokau opened this issue May 23, 2022 · 2 comments

Comments

@timokau
Copy link
Contributor

timokau commented May 23, 2022

Hi,

currently calling predict on an uninitialized estimator throws a NotInitializedError instead of scikit-learn's NotFittedError. This is problematic in cases where we want to be able to handle different kinds of estimators while providing some kind of fallback behavior. Currently we need

try:
    prediction = estimator.predict(X)
except (NotFittedError, NotInitializedError):
    # some fallback behavior

I think it would be better if NotInitializedError was a subclass of NotFittedError. In that case we could treat an skorch estimator like a regular scikit-learn estimator and simply catch NotFittedError.

Would a PR in that direction be welcome?

@BenjaminBossan
Copy link
Collaborator

Thanks for the suggestion, sounds indeed like a good idea. PR is welcome.

timokau added a commit to timokau/skorch that referenced this issue May 24, 2022
This ensures that a user can catch the sklearn `NotFittedError`, just as
they can with regular sklearn estimators. As discussed in [1].

[1] skorch-dev#859
@timokau
Copy link
Contributor Author

timokau commented May 24, 2022

Great :) See #860.

@timokau timokau closed this as completed May 24, 2022
BenjaminBossan pushed a commit that referenced this issue May 24, 2022
This ensures that a user can catch the sklearn `NotFittedError`, just as
they can with regular sklearn estimators. As discussed in [1].

[1] #859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants