fusionlab.plot.evaluation.plot_mean_interval_width¶
- fusionlab.plot.evaluation.plot_mean_interval_width(y_lower, y_upper, miw_values=None, metric_kws=None, kind='summary_bar', output_idx=None, hist_bins='auto', hist_color='mediumpurple', hist_edgecolor='black', figsize=(10, 6), title='Mean Interval Width (Sharpness)', xlabel=None, ylabel=None, bar_color='mediumpurple', bar_width=0.8, score_annotation_format='{:.4f}', show_score=True, show_grid=True, grid_props=None, ax=None, verbose=0, **kwargs)[source]¶
Visualise Mean Interval Width (MIW) – a simple sharpness measure equal to the average distance between lower and upper prediction‐ interval bounds.
Two complementary views are implemented:
‘widths_histogram’ – distribution of individual interval widths for a chosen output.
‘summary_bar’ – bar chart of the averaged width (overall or one bar per output).
- Parameters:
y_lower (
ndarray) – Lower‑bound quantile (e.g. 0.05 or 0.10) for an uncertainty interval. Shape must mirror y_true. Required by coverage,y_upper (
ndarray) – Upper‑bound quantile (e.g. 0.95 or 0.90) paired with y_lower.miw_values (
floatorndarray, optional) – Pre‑computed MIW score(s). If supplied the helper skips the internal call tofusionlab.metrics.mean_interval_width_score().metric_kws (
dict, optional) – Extra keyword arguments forwarded tofusionlab.metrics.mean_interval_width_score().kind (
{'widths_histogram', 'summary_bar'},) – default'summary_bar'Select the visualisation style.output_idx (
int, optional) – Output dimension to plot whenkind='widths_histogram'on multi‑output data.hist_bins (
int | sequence | str, default :class:``’auto’:class:``)hist_color (
str, default :class:``’mediumpurple’:class:``)hist_edgecolor (
str, default :class:``’black’:class:``) – Styling options for the histogram.figsize (
tupleoffloat, optional) – Size of the figure in inches (width, height). If omitted thetitle (
str, optional) – Main title for the figure. If None, a context‑aware defaultxlabel (
str, optional) – Label for the x‑axis. If None, a function‑specific default isylabel (
str, optional) – Label for the y‑axis. If None, a context‑sensitive default isbar_color (
strorlistofstr, optional) – Bar face‑colour(s). Accepts any Matplotlib‑recognised colourbar_width (
float, default0.8)score_annotation_format (
str, default'{:.4f}') – Python format string used for numeric annotations. Examples:show_score (
bool, defaultTrue) – Display the mean width on the histogram title.show_grid (
bool, defaultTrue)grid_props (
dict, optional) – Keyword arguments forwarded toAxes.gridfor fine‑grainedax (
matplotlib.axes.Axes, optional) – Existing Matplotlib axes to draw on. If None, a new figureverbose (
int, default0) – Verbosity level. 0 ⇒ silent, 1 ⇒ basic info, 2+ ⇒ debug**kwargs – Additional keyword arguments passed directly to the underlying Matplotlib primitives (
plot,scatter,bar,
- Returns:
Axes containing the MIW visualisation.
- Return type:
matplotlib.axes.Axes
Notes
For a single observation the interval width is simply
\[w_i \;=\; u_i \;-\; \ell_i ,\]where \(u_i\) and \(\ell_i\) are the upper and lower bounds. The mean interval width over N samples is
\[\text{MIW} \;=\; \frac{1}{N}\sum_{i=1}^{N} w_i.\]Lower MIW indicates a sharper forecast, but should always be interpreted together with coverage diagnostics.
Examples
>>> import numpy as np, matplotlib.pyplot as plt >>> from fusionlab.plot.evaluation import plot_mean_interval_width >>> rng = np.random.default_rng(1) >>> y_l = rng.normal(loc=-1.0, scale=.5, size=200) >>> y_u = y_l + rng.uniform(1.5, 2.5, size=200) >>> plot_mean_interval_width( ... y_lower=y_l, y_upper=y_u, kind='widths_histogram', ... figsize=(8, 4)) >>> plt.show()
See also
fusionlab.metrics.mean_interval_width_scoreNumeric computation of MIW.
fusionlab.plot.evaluation.plot_coverageShows how many observations fall inside the intervals.
fusionlab.plot.evaluation.plot_weighted_interval_scoreCombines width with calibration penalties.
References