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

GroupedPredictor patch #619

Merged
merged 6 commits into from
Feb 27, 2024
Merged

Conversation

FBruzzesi
Copy link
Collaborator

Description

As discussed in #616, shrinkage was intended for regression problems and even if in some cases it doesn't raise errors, it would yield incorrect results for classification or outlier detection tasks.

This PR:

  • Early raises an error for shrinkage in non-regression tasks
  • Expands on GroupedPredictor docstring
  • Adds two classes, GroupedRegressor and GroupedClassifier - the latter doesn't allow for shrinkage in __init__
  • Fixes image rendering in docs
  • Removed GroupedEstimator as we passes 0.7.0

Fixes #616

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 (flake8)
  • 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

super().__init__(
estimator=estimator,
groups=groups,
shrinkage=None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forcing shrinkage to be None

<p align="center">
<img src="../_static/meta-models/grouped-model.png" />
</p>
![grouped-model](../_static/meta-models/grouped-model.png)
Copy link
Owner

@koaning koaning Feb 20, 2024

Choose a reason for hiding this comment

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

Do we want to mention the classifier/regressor objects in the docs here maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds reasonable

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.

Looks great, but found a few talking points.

def test_specialized_classes(meta_cls, estimator, context):
df = load_chicken(as_frame=True)
with context:
meta_cls(estimator=estimator, groups="diet").fit(df[["time", "diet"]], df["weight"].astype(int))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Specialized classes raise with wrong estimator type

(lambda x: x, pytest.raises(ValueError)),
],
)
def test_clf_shrinkage(shrinkage, context):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GroupedPredictor with a classifier raises if shrinkage is not None now

Its equivalent to [`GroupedPredictor`][sklego.meta.grouped_predictor.GroupedPredictor] with `shrinkage=None`
but it is available only for classification models.

!!! info "New in version 0.7.5"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do you feel about this?

Proof of rendering:
image

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.

LGTM!

@koaning koaning merged commit 507faef into koaning:main Feb 27, 2024
14 checks passed
@koaning
Copy link
Owner

koaning commented Feb 27, 2024

@FBruzzesi Any concerns about releasing this right away?

@FBruzzesi
Copy link
Collaborator Author

@FBruzzesi Any concerns about releasing this right away?

Not sure if it's better to go 0.7.5 (as in the info admonitions) or to 0.8.0 as it has breaking changes (no more shrinkage for classification).

If you want to wait for the HierarchicalPredictors, I may need a few more days just to open the PR

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.

[BUG] Error when calling predict_proba with GroupedPredictor using shrinkage and global model
2 participants