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

feat: ZeroInflatedRegressor.score_samples(...) #680

Merged
merged 6 commits into from
Jul 8, 2024

Conversation

FBruzzesi
Copy link
Collaborator

Description

Implements score_samples for ZeroInflatedRegressor as discusses in #585

Fixes #585

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the style guidelines (ruff)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (also to the readme.md)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added tests to check whether the new feature adheres to the sklearn convention
  • New and existing unit tests pass locally with my changes

Comment on lines +126 to +127
with pytest.raises(AttributeError, match="This 'ZeroInflatedRegressor' has no attribute 'score_samples'"):
zir.score_samples(X)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wondering if this is the best error message to give to the user - automatically generated from available_if decorator

Comment on lines 391 to 393
If the underlying classifier is able to predict the _probability_ of a sample to be zero (i.e. it implements a `predict_proba` method), then the `ZeroInflatedRegressor` can be used to predict the probability of a sample being non-zero times the expected value of such sample.

This quantity is sometimes called _risk estimate_ or _expected impact_, however, to adhere to scikit-learn convention, we made it accessible via the `score_samples` method.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cc: @edgBR

Is this description reasonable to you? Any input is more than welcomed

Copy link
Owner

Choose a reason for hiding this comment

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

@edgBR reminder ping

Copy link

Choose a reason for hiding this comment

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

Hi guys, the description looks clear to me. However I will add that it can be called risk only if the classifier is calibrated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will add a warning to mention that classifier should be calibrated

Copy link
Owner

@koaning koaning left a comment

Choose a reason for hiding this comment

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

Did not spot anything out of the ordinary, feels cool to merge to me.

@FBruzzesi let me know if you merge this because it feels like it would be ready for a new release as well.

@FBruzzesi
Copy link
Collaborator Author

I was out on vacation for the weekend. Merging now 😁

@FBruzzesi FBruzzesi merged commit d8a165e into main Jul 8, 2024
18 checks passed
@FBruzzesi FBruzzesi deleted the feat/zir-score-samples branch July 8, 2024 07:00
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

Successfully merging this pull request may close these issues.

[FEATURE] Implement predict proba in ZeroInflatedRegressor()
3 participants