Skip to content

ENH auto-detect built-in CI in plot_metric_frame - #1674

Merged
romanlutz merged 2 commits into
fairlearn:mainfrom
DresdenGman:enh-1487-metricframe-ci-plot
Jul 11, 2026
Merged

romanlutz merged 2 commits into
fairlearn:mainfrom
DresdenGman:enh-1487-metricframe-ci-plot

Conversation

@DresdenGman

Copy link
Copy Markdown
Contributor

Addresses #1487.

This PR lets plot_metric_frame use the confidence intervals already computed by MetricFrame when it was constructed with n_boot and ci_quantiles.

When conf_intervals is not provided, the plotting helper now detects the built-in by_group_ci results and converts them into the existing error-bar path. If users pass conf_intervals explicitly, that existing behavior continues to take precedence.

This keeps the change internal to the plotting bridge and does not add a new public API. I added tests for single-metric and multi-metric MetricFrame plots, the no-bootstrap fallback, and the explicit conf_intervals override path.

@romanlutz romanlutz left a comment

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.

Thanks a lot for the contribution! I left a few comments. Let me know if you want me to help in addressing them.

Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
@DresdenGman
DresdenGman force-pushed the enh-1487-metricframe-ci-plot branch from d810c8c to 5a15d29 Compare July 9, 2026 12:42
@DresdenGman

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review — really helpful.

I've reworked the helper to use the public by_group_ci and ci_quantiles instead of reaching into _result_cache, and it now returns a {metric: ci_col} mapping so the auto-detect can be wired up after metrics are resolved. That should fix both the reorder bug and the subset crash.

Also handled the quantile edge cases — >2 quantiles now warns and picks the outermost pair, and reversed order is sorted before splitting. Added tests for all of those. Docstring and changelog are updated too. And I pulled out the adversarial mitigation change since it's already #1673.

@DresdenGman

Copy link
Copy Markdown
Contributor Author

Good catch on both — I've added the to_frame() normalisation before the metrics loop so single-metric Series works again, and switched g_1.unique() to np.unique(g_1) in the tests.

@romanlutz
romanlutz merged commit 36b0514 into fairlearn:main Jul 11, 2026
69 of 70 checks passed
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.

2 participants