Skip to content

Mixed array namespace input for explained_variance_score, mean_squared_log_error, median_absolute_error, r2_score, root_mean_squared_log_error - #33515

Merged
OmarManzoor merged 2 commits into
scikit-learn:mainfrom
betatim:metrics-mixed-input-2
Mar 11, 2026

Conversation

@betatim

@betatim betatim commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #26024
Follow up of #32755

What does this implement/fix? Explain your changes.

Adds mixed array namespace input for explained_variance_score, mean_squared_log_error, median_absolute_error, r2_score, root_mean_squared_log_error.

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?

I think the way we handle multioutput needs thinking about. In particular when a user passes a numpy array or a list of weights. I think it will not get moved to the right namespace/device. This problem already exists so I didn't try to fix it. If y'all agree that there is something to fix I can make a new PR/issue for this.

explained_variance_score, mean_squared_log_error,
median_absolute_error, r2_score, root_mean_squared_log_error.

@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 @betatim

@OmarManzoor

Copy link
Copy Markdown
Contributor

I think this can be merged too but there is a comment in the description which requires some input from other maintainers too. Plus there is a conflict.

@OmarManzoor OmarManzoor added the Waiting for Second Reviewer First reviewer is done, need a second one! label Mar 11, 2026
@betatim

betatim commented Mar 11, 2026

Copy link
Copy Markdown
Member Author

I resolved the conflict. Agree that getting a few eyes on the comment is important, but I think it should be handled in a new PR

@OmarManzoor

Copy link
Copy Markdown
Contributor

I agree that it should be handled in a new PR. Let's merge this then. The comment can still be discussed.

@OmarManzoor
OmarManzoor enabled auto-merge (squash) March 11, 2026 12:54
@OmarManzoor
OmarManzoor merged commit 3bbf8d9 into scikit-learn:main Mar 11, 2026
30 checks passed
@betatim
betatim deleted the metrics-mixed-input-2 branch March 11, 2026 13:50
@betatim

betatim commented Mar 11, 2026

Copy link
Copy Markdown
Member Author

I created an issue to discuss this #33519

@lucyleeow

lucyleeow commented Mar 20, 2026 •

Copy link
Copy Markdown
Member

I've just remembered why regression and classification metric support was not added in the original PR #32755 - we had discussed including this in a common function (e.g., check_targets/_check_reg_targets) and since that is a big change, I thought it should be handled in a separate PR. Sorry I should have re-iterated (and remembered) this as we were finishing up that PR.

See: #32755 (comment)

I was going to add mixed array input support to a classification metric but looking at it, I realise it would probably be easier/better to implement this by amending check_targets (or similar), to avoid duplicate check_array etc calls, and may allow us to add mixed array support for all classification metrics.

@ogrisel had actually done this (and originally suggested it) for regression metrics in his pipeline test PR #32873, see #32755 (comment)

ping @ogrisel @betatim @OmarManzoor if we still/all agree that this would be a good idea?
Sorry for redundancy of effort, but it would mean we don't have to do this for any future metrics. If we agree maybe we could move (at least y and sample_weight handling, I know #33519 is open) to a common check?

@lucyleeow

Copy link
Copy Markdown
Member

Ideally we'd be able to get rid of METRICS_SUPPORTING_MIXED_NAMESPACE as well, but I think the continuous metrics in _ranking.py cannot be handled as simply and will need to be added one by one (?). We can instead just add all the regression and non continuous classification metrics - these are already defined in a variable in test_common.py I think.

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

Labels

Array API module:metrics No Changelog Needed Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants