FIX Propagate pairwise tag from wrapped regressor in TransformedTarge⦠- #34810
Open
RohanMukka wants to merge 2 commits into
Open
FIX Propagate pairwise tag from wrapped regressor in TransformedTargeβ¦#34810RohanMukka wants to merge 2 commits into
RohanMukka wants to merge 2 commits into
Conversation
β¦tRegressor TransformedTargetRegressor.__sklearn_tags__ already propagated the sparse and multi_output tags from the wrapped regressor, but not the pairwise tag. As a result, wrapping a pairwise estimator (e.g. KNeighborsRegressor with metric="precomputed") caused GridSearchCV/_safe_split to treat a precomputed distance matrix as regular feature data and split it by rows, raising "Precomputed matrix must be square". Closes scikit-learn#22828
|
Thank you for opening your first pull request to scikit-learn! π To help get your contribution reviewed, please make sure that:
|
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.
Reference Issues/PRs
Closes #22828
What does this implement/fix? Explain your changes.
TransformedTargetRegressor.__sklearn_tags__already propagates thesparseand
multi_outputtags from the wrapped regressor, but notpairwise. As aresult, wrapping a pairwise estimator (e.g.
KNeighborsRegressor(metric= "precomputed")) in aTransformedTargetRegressorloses that information,so
GridSearchCV/cross_val_scoretreat a precomputed distance matrix asordinary feature data and split it by rows via
_safe_split, raising"Precomputed matrix must be square". This adds the missing tag propagation,
following the same pattern already used for
sparse/multi_outputin thesame method (and for
pairwiseitself inPipeline.__sklearn_tags__).Added a non-regression test reproducing the original
GridSearchCVfailurefrom the issue, plus a direct test on the propagated tag.
Introduce yourself
This is my second scikit-learn contribution attempt β my first PR (#34784)
got closed because I didn't follow guidance already in the issue thread. This
time I read the full issue discussion and verified the fix by reproducing
the actual error against current
mainbefore opening this PR.AI usage disclosure
I used AI assistance for:
Any other comments?
No maintainer has commented on this issue yet, so the approach (propagating
the
pairwisetag, matching howPipelinealready does it) hasn't beenpre-confirmed. Happy to adjust if a maintainer suggests a different fix.