Fix #1328: Update ContribEstimator wrapper to work with sklearn 1.6+ tags API#1333
Open
edschofield wants to merge 2 commits intoDistrictDataLabs:developfrom
Open
Fix #1328: Update ContribEstimator wrapper to work with sklearn 1.6+ tags API#1333edschofield wants to merge 2 commits intoDistrictDataLabs:developfrom
edschofield wants to merge 2 commits intoDistrictDataLabs:developfrom
Conversation
…gressor(), is_clusterer() do not work with sklearn 1.8
…ork with sklearn 1.6+ tags API Starting in scikit-learn 1.6, the type-checking functions is_classifier(), is_regressor(), is_clusterer(), and is_outlier_detector() were changed to use a new tags-based mechanism. Instead of inspecting the _estimator_type attribute directly, they now call get_tags(estimator), which in turn invokes estimator.__sklearn_tags__() and checks the estimator_type field on the returned Tags dataclass. ContribEstimator did not implement __sklearn_tags__(), so when sklearn called it, the call fell through to ContribEstimator.__getattr__(), which proxied it to the wrapped third-party estimator. Since third-party estimators (the whole reason ContribEstimator exists) typically don't implement __sklearn_tags__() either, this raised an AttributeError, causing all four type checks to fail. The fix adds a __sklearn_tags__() method to ContribEstimator that builds a default Tags object (via BaseEstimator) and replaces the estimator_type field with the value from self._estimator_type when set. This preserves the existing behavior where wrap(est, "classifier") makes the estimator pass is_classifier() checks, while remaining forward-compatible with sklearn's tags infrastructure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Starting in scikit-learn 1.6, the type-checking functions is_classifier(), is_regressor(),etc. were changed to use a new tags-based mechanism. Yellowbrick's ContribEstimator did not implement
__sklearn_tags__(),so when sklearn called it, the call fell through to ContribEstimator.getattr(). Since third-party estimators (the whole reason ContribEstimator exists) typically don't implement sklearn_tags() either, this raised an AttributeError, causing all four type checks to fail.This fix adds a
__sklearn_tags__()method to ContribEstimator that builds a default Tags object (via BaseEstimator) and replaces the estimator_type field with the value from self._estimator_type when set. This preserves the existing behavior wherewrap(est, "classifier")makes the estimator passis_classifier()checks, while remaining forward-compatible with sklearn's tags infrastructure.After applying this fix, the tests that @jakevdp reported in #1328 to be failing now pass.