Skip to content

FIX Propagate pairwise tag from wrapped regressor in TransformedTarge… - #34810

Open
RohanMukka wants to merge 2 commits into
scikit-learn:mainfrom
RohanMukka:fix/22828-ttr-pairwise-tag
Open

FIX Propagate pairwise tag from wrapped regressor in TransformedTarge…#34810
RohanMukka wants to merge 2 commits into
scikit-learn:mainfrom
RohanMukka:fix/22828-ttr-pairwise-tag

Conversation

@RohanMukka

Copy link
Copy Markdown

Reference Issues/PRs

Closes #22828

What does this implement/fix? Explain your changes.

TransformedTargetRegressor.__sklearn_tags__ already propagates the sparse
and multi_output tags from the wrapped regressor, but not pairwise. As a
result, wrapping a pairwise estimator (e.g. KNeighborsRegressor(metric= "precomputed")) in a TransformedTargetRegressor loses that information,
so GridSearchCV/cross_val_score treat a precomputed distance matrix as
ordinary 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_output in the
same method (and for pairwise itself in Pipeline.__sklearn_tags__).

Added a non-regression test reproducing the original GridSearchCV failure
from 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 main before opening this PR.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Research and understanding

Any other comments?

No maintainer has commented on this issue yet, so the approach (propagating
the pairwise tag, matching how Pipeline already does it) hasn't been
pre-confirmed. Happy to adjust if a maintainer suggests a different fix.

…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
Copilot AI lite review requested due to automatic review settings August 25, 2026 00:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! πŸŽ‰

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.

  • The pull request addresses an existing issue that is ready for contribution (e.g. not tagged as 'Needs Triage', 'Needs Decision', ...). If you are proposing a new feature, please open an issue to discuss it first.

  • There are no other open pull requests already targeting the same issue.

  • You have followed the pull request checklist. In particular, linting and tests should pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gridsearch on TransformedTargetRegressor on pairwise data

2 participants