fusionlab.plot.evaluation.plot_prediction_stability¶
- fusionlab.plot.evaluation.plot_prediction_stability(y_pred, pss_values=None, metric_kws=None, kind='summary_bar', output_idx=None, hist_bins='auto', hist_color='teal', hist_edgecolor='black', figsize=(10, 6), title='Prediction Stability Score (PSS)', xlabel=None, ylabel=None, bar_color='teal', bar_width=0.8, score_annotation_format='{:.4f}', show_score=True, show_grid=True, grid_props=None, ax=None, verbose=0, **kwargs)[source]¶
Visualise the Prediction Stability Score (PSS) — the average absolute change between successive time steps in a forecast trajectory. Lower PSS ⇒ smoother (more stable) predictions.
Two complementary views are provided:
‘scores_histogram’ – distribution of per‑trajectory PSS values for a chosen output.
‘summary_bar’ – bar chart of the mean PSS (overall or one bar per output).
- Parameters:
y_pred (
ndarray) – Model predictions. Accepts * 1‑D(T,)– single trajectory, one output; * 2‑D(N, T)– N trajectories, one output; * 3‑D(N, O, T)– N trajectories, O outputs. The final dimension is the temporal axis (T ≥ 2 for PSS).pss_values (
floatorndarray, optional) – Pre‑computed PSS value(s). If supplied the helper skips internal calls tofusionlab.metrics.prediction_stability_score().metric_kws (
dict, optional) – Extra keyword arguments forwarded to the metric function.kind (
{'scores_histogram', 'summary_bar'},) – default'summary_bar'Select the visualisation style.output_idx (
int, optional) – Output dimension to plot whenkind='scores_histogram'on multi‑output data.hist_bins (
int | sequence | str, default :class:``’auto’:class:``)hist_color (
str, default :class:``’teal’: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 PSS 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 stability visualisation.
- Return type:
matplotlib.axes.Axes
Notes
For one trajectory \((\hat y_{1},\dots,\hat y_{T})\) the stability score is
\[\operatorname{PSS} \;=\; \frac{1}{T-1}\sum_{t=2}^{T} \bigl|\hat y_{t} - \hat y_{t-1}\bigr|.\]The helper first reshapes
y_predto (N, O, T), computes the per‑trajectory scores, and then aggregates or plots them according tokind.Examples
>>> import numpy as np, matplotlib.pyplot as plt >>> from fusionlab.plot.evaluation import plot_prediction_stability >>> rng = np.random.default_rng(0) >>> preds = rng.normal(size=(200, 30)) # 200 series, 30 time steps >>> plot_prediction_stability( ... preds, kind='scores_histogram', figsize=(8, 4)) >>> plt.show()
See also
fusionlab.metrics.prediction_stability_scoreNumeric implementation of PSS.
fusionlab.plot.evaluation.plot_time_weighted_metricTime‑weighted MAE, accuracy, and interval‑score plots.
References