Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Move mixed array input support of regression metrics to _check_reg_targets - #33778

Merged
OmarManzoor merged 46 commits into
scikit-learn:mainfrom
lucyleeow:mixed_array_reg
Jul 13, 2026
Merged

Move mixed array input support of regression metrics to _check_reg_targets#33778
OmarManzoor merged 46 commits into
scikit-learn:mainfrom
lucyleeow:mixed_array_reg

Conversation

@lucyleeow

@lucyleeow lucyleeow commented Apr 17, 2026

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #33519 (still need to address for classification metrics and add appropriate tests)
Follows from #32755
As discussed in #33515 (comment)
Based off of @ogrisel 's work in https://github.com/scikit-learn/scikit-learn/pull/32873/files#diff-937b82251fd52d1911b5046edef599c244a155f70b00d730f1eeb25be133a8a1 (see thread #32755 (comment))

What does this implement/fix? Explain your changes.

Adds support of mixed array namespace/device input to the common _check_reg_targets that is used in all regression metrics. This means that all regression metrics automatically support mixed array inputs when it uses _check_reg_targets

AI usage disclosure

I used AI assistance for:

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

Any other comments?

No changelog as I think all reg metrics already supported mixed array inputs.

y_true, sample_weight = move_to(y_true, sample_weight, xp=xp, device=device)
xp, _, device_ = get_namespace_and_device(y_pred)
_, y_true, y_pred, sample_weight, multioutput = (
_check_reg_targets_with_floating_dtype(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've added _check_reg_targets_with_floating_dtype here, even though it was not here previously, as it calls mean_squared_error, which performs this check because multioutput is otherwise not checked to ensure it is valid. This makes it more consistent, ensuring the same informative error is raised if multioutput is not valid

@ogrisel

ogrisel commented Apr 17, 2026

Copy link
Copy Markdown
Member

Some tests fail with pandas inputs. I haven't looked at the details but feel free to ping me again once you have a fix for this.

@adrinjalali adrinjalali added this to Labs Apr 20, 2026
@adrinjalali adrinjalali moved this to In progress in Labs Apr 20, 2026
Comment thread sklearn/metrics/_regression.py Outdated
@lucyleeow

Copy link
Copy Markdown
Member Author

I think this is ready for a review now @ogrisel, thank you!

@ogrisel

ogrisel commented Jul 6, 2026

Copy link
Copy Markdown
Member

Sorry I may have missed this, but why did it not work in cross-validated pipelines?

I mean that it's not possible to cross-validate regression pipelines that move X to GPU in some intermediate step with any of the supported regression metrics from the updated METRICS_SUPPORTING_MIXED_NAMESPACE list.

Basically the kind of thing I was trying to get working in test_cross_validate_array_api_pipeline from #32873.

Comment thread sklearn/metrics/_regression.py Outdated
# `torch.median` takes the lower of the two medians when `x` has even number
# of elements, thus we use `torch.quantile(q=0.5)`, which gives mean of the two
if array_api_compat.is_torch_namespace(xp):
# torch `quantile` only accepts floats

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 for adding a new test case for int inputs for _array_api.py functions. Feel free to ping me once done.

@lucyleeow

Copy link
Copy Markdown
Member Author

I mean that it's not possible to cross-validate regression pipelines that move X to GPU in some intermediate step with any of the supported regression metrics from the updated METRICS_SUPPORTING_MIXED_NAMESPACE list.

Sorry, I wasn't sure if you were referring to something else.

I've double checked and everything was already covered in #33515 and #33511 - there are 21 metrics in REGRESSION and there were 21 metrics removed in METRICS_SUPPORTING_MIXED_NAMESPACE

@lucyleeow lucyleeow added the Waiting for Second Reviewer First reviewer is done, need a second one! label Jul 7, 2026
@lucyleeow

Copy link
Copy Markdown
Member Author

ping @virchan @OmarManzoor

@OmarManzoor OmarManzoor 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.

Mostly looks good just a few comments. Thank you for the PR @lucyleeow

Comment thread sklearn/metrics/_regression.py Outdated
Comment thread sklearn/metrics/_regression.py Outdated
Comment thread sklearn/metrics/_regression.py Outdated
Comment thread sklearn/metrics/_regression.py Outdated

@OmarManzoor OmarManzoor 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.

LGTM. Thank you @lucyleeow

@OmarManzoor
OmarManzoor merged commit 46d6402 into scikit-learn:main Jul 13, 2026
42 of 43 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Array API Jul 13, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Done in Labs Jul 13, 2026
@lucyleeow
lucyleeow deleted the mixed_array_reg branch July 13, 2026 09:40
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants