Skip to content

feat: accept metric names without neg_ prefix in summarize()#2656

Open
direkkakkar319-ops wants to merge 9 commits intoprobabl-ai:mainfrom
direkkakkar319-ops:issue#2607-DirekKakkar
Open

feat: accept metric names without neg_ prefix in summarize()#2656
direkkakkar319-ops wants to merge 9 commits intoprobabl-ai:mainfrom
direkkakkar319-ops:issue#2607-DirekKakkar

Conversation

@direkkakkar319-ops
Copy link
Copy Markdown
Contributor

Description

Fixes #2607
When using report.metrics.summarize(), passing error metric names without the neg_ prefix (e.g. "mean_squared_error") would raise a ValueError because sklearn's scorer registry only knows the neg_ .

Root Cause

Sklearn follows a "higher is better" convention for all scorers.
Error metrics like mean_squared_error are therefore only registered as neg_mean_squared_error in sklearn's scorer registry.

Solution

Added a _METRIC_ALIASES dictionary inside _MetricsAccessor that maps user-friendly metric names to their neg_ prefixed sklearn scorer equivalents.

_METRIC_ALIASES: dict[str, str] = {
    "mean_squared_error": "neg_mean_squared_error",
    ...
}

Changes

  • skore/src/skore/_sklearn/_estimator/metrics_accessor.py — added _METRIC_ALIASES dict and resolution logic in summarize()
  • In skore/src/skore/_sklearn/_estimator/metrics_accessor.py
    made this code
image

to

image
  • skore/tests/unit/reports/estimator/metrics/test_metric_aliases.py — added test cases for the fix
  • sphinx/changelog.rst — updated changelog

Testing

# Before this fix — raised ValueError
report.metrics.summarize(metric='mean_squared_error').frame()

# After this fix-working correct
report.metrics.summarize(metric='mean_squared_error').frame()
report.metrics.summarize(metric='neg_mean_squared_error').frame()  # still works too
Screenshot 2026-03-21 203902

@direkkakkar319-ops direkkakkar319-ops marked this pull request as ready for review March 21, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Make it possible to pass sklearn metrics without "neg_"

1 participant