fusionlab.plot.evaluation.plot_metric_radar

fusionlab.plot.evaluation.plot_metric_radar(forecast_df, segment_col, metric='mae', target_name='target', quantiles=None, output_dim=1, actual_col_pattern='{target_name}_actual', pred_col_pattern_point='{target_name}_pred', pred_col_pattern_quantile='{target_name}_q{quantile_int}', aggregate_across_horizon=True, scaler=None, scaler_feature_names=None, target_idx_in_scaler=None, figsize=(8, 8), max_segments_to_plot=12, verbose=0, **plot_kwargs)[source]

Visualise a chosen error metric per segment on a radar chart.

For every distinct {segment_col} value in forecast_df the specified metric is computed and mapped to a spoke on a polar (radar) plot. Point‑forecast and quantile‑forecast frames are both supported.  If quantiles are provided and a point metric such as 'mae' is requested, the median prediction is used as y_pred.

The helper is designed for data produced by fusionlab.nn.utils.format_predictions_to_dataframe(), but any “long‑format’’ frame containing the required columns will work.

Parameters:
  • forecast_df (pandas.DataFrame) – Long‑format table of predictions. Must contain 'sample_idx' and 'forecast_step' plus the prediction, {segment_col}, and actual columns (for instance

  • segment_col (str) – Column whose unique values form the radar spokes

  • metric (str or Callable, default :class:``’mae’:class:``) – Metric to compute per segment. Accepted names: 'mae', 'mse', 'rmse', 'mape', 'smape'. For a custom metric pass a function f(y_true, y_pred) -> float. When quantiles are supplied the median prediction is forwarded

  • target_name (str, default :class:``”target”:class:``)

  • quantiles (list[float], optional) – Quantiles included in forecast_df (e.g. [0.1, 0.5, 0.9]). If present and a generic metric is chosen the median (0.5 or nearest) prediction is employed as y_pred.

  • output_dim (int, default 1) – Number of target dimensions. A separate radar is generated

  • actual_col_pattern (str, default :class:``”{target_name}_actual”:class:``) – Format string for locating actual columns.

  • pred_col_pattern_point (str, default :class:``”{target_name}_pred”:class:``)

  • pred_col_pattern_quantile (str, default) – "{target_name}_q{quantile_int}" Format string for quantile columns.

  • aggregate_across_horizon (bool, default True) – If True the metric is computed on all time‑steps per segment. If False the caller must provide pre‑aggregated values or expect

  • scaler (Any, optional) – Fitted scikit‑learn‑style transformer used to inverse‑scale data

  • scaler_feature_names (list[str], optional) – Full feature order that scaler was trained on.

  • target_idx_in_scaler (int, optional) – Position of target_name inside scaler_feature_names.

  • figsize (tuple[float, `:class:`float], default :class:`(8`:class:`, `:class:`8)`)

  • max_segments_to_plot (int, optional) – Hard cap on the number of segments shown on one radar.

  • verbose (int, default 0)

  • **plot_kwargs (Any) – Extra arguments forwarded to the underlying Matplotlib ax.plot / ax.fill calls (e.g. color, linewidth,

Returns:

The function displays one or more radar charts using Matplotlib and does not return a value.

Return type:

None

Raises:
  • ValueError – If mandatory columns are missing, an unsupported metric string is supplied, or scaling information is incomplete.

  • TypeError – If forecast_df is not a pandas.DataFrame, or metric is neither a recognised string nor a callable.

Notes

Radar plots benefit from a modest number of axes.  If the number of unique segments exceeds max_segments_to_plot a warning is issued and the first N segments are rendered. Consider filtering or aggregating rare categories beforehand.

See also

fusionlab.plot.evaluation.plot_metric_over_horizon

Line / bar visualiser of the same metrics over forecast step.

fusionlab.metrics.

Collection of metric implementations (MAE, MAPE, …).

Examples

>>> import numpy as np, pandas as pd
>>> from fusionlab.nn.utils import format_predictions_to_dataframe
>>> from fusionlab.plot.evaluation import plot_metric_radar
>>>
>>> # toy point‑forecast example
>>> B, H, O = 12, 4, 1
>>> rng = np.random.default_rng(0)
>>> preds = rng.normal(size=(B, H, O))
>>> y_true = preds + rng.normal(scale=.25, size=(B, H, O))
>>> df = format_predictions_to_dataframe(
...     preds, y_true, target_name="sales",
...     forecast_horizon=H, output_dim=O
... )
>>> df["store"] = rng.choice(["A", "B", "C"], size=len(df))
>>>
>>> plot_metric_radar(
...     forecast_df=df,
...     segment_col="store",
...     metric="rmse",
...     target_name="sales",
... )

References