Skip to content

TST Add test for multiclass input format invariance, fix average_precision_error - #34083

Merged
lucyleeow merged 5 commits into
scikit-learn:mainfrom
lucyleeow:multiclass_test
May 23, 2026
Merged

lucyleeow merged 5 commits into
scikit-learn:mainfrom
lucyleeow:multiclass_test

Conversation

@lucyleeow

@lucyleeow lucyleeow commented May 22, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

ref: #32909 (comment)

What does this implement/fix? Explain your changes.

  • Add test that checks input invariance (list vs array) for continuous multiclass metrics
  • Fixes average_precision_score to accept list

AI usage disclosure

I used AI assistance for:

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

Any other comments?

cc @StefanieSenger

0.77
"""
xp, _, device = get_namespace_and_device(y_score)
y_score = check_array(y_score, ensure_2d=False)

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.

Looking at other metrics, this was the standard way to ensure lists/other array types are converted to numpy arrays.

Comment on lines +338 to +342
"label_ranking_loss",
"label_ranking_average_precision_score",
"dcg_score",
"ndcg_score",
"coverage_error",

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.

None of these accept multiclass inputs - they generally deal with ranking and multilabel (not multiclass)

@lucyleeow

Copy link
Copy Markdown
Member Author

Actually I should probably add a changelog here

Comment thread sklearn/metrics/tests/test_common.py Resolved
@ogrisel

ogrisel commented May 22, 2026

Copy link
Copy Markdown
Member

Feel free to merge with a changelog entry.

@lucyleeow
lucyleeow enabled auto-merge (squash) May 23, 2026 01:20
@lucyleeow
lucyleeow merged commit 0f0ff8c into scikit-learn:main May 23, 2026
33 checks passed
@lucyleeow
lucyleeow deleted the multiclass_test branch May 23, 2026 02:03
@jeremiedbb jeremiedbb mentioned this pull request Jun 1, 2026
16 tasks done
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
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.

2 participants