convert.predictions_to_datatree()
Pack prediction draws into a DataTree laid out for per-series plot_lm faceting.
Usage
convert.predictions_to_datatree(
predictions, x, series, *, group="posterior_predictive", observed=None
)The array-level counterpart of to_datatree(): instead of a fit, it takes prediction draws from any predictive group (prior predictive, posterior predictive, or forecasts), possibly already transformed (rescaled to original units, clipped at zero, subset to a few series). The draws get a single pseudo-chain, and constant_data carries the independent variable "t" broadcast to (time, series) so that arviz.plot_lm(tree, y="obs", x="t", plot_dim="time", ...) facets one panel per series; band artists are then reachable via pc.viz["ci_band"]["t"] and axes via pc.get_target("t", {"series": label}).
plot_lm requires an observed_data group even when the observation scatter is disabled, so when observed is None a zeros placeholder is stored; it is never drawn under visuals={"observed_scatter": False}.
Parameters
predictions: Float[np.ndarray | Array, " sample time series"]-
Prediction draws with the sample axis first, shape
(sample, time, series). x: Num[np.ndarray | Array, " time"]-
Independent-variable values, shape
(time,). Must be numeric:plot_lmcannot drawdatetime64values (it concatenatesxwith the float predictions internally), so passmatplotlib.dates.date2num()floats and re-format the tick labels withmatplotlib.dates.ConciseDateFormatter. series: Sequence[Any]-
One label per series, defining the
seriescoordinate. group: str = "posterior_predictive"-
Predictive group to store the draws under (e.g.
"prior_predictive","posterior_predictive","predictions"). observed: Float[np.ndarray | Array, " time series"] | None = None-
Optional observations, shape
(time, series), stored inobserved_data; whenNonea zeros placeholder is stored instead.
Returns
xarray.DataTree-
A tree with the
group,observed_data, andconstant_datagroups;obshas dims(chain, draw, time, series)andthas dims(time, series).
Raises
ValueError-
If
seriesdoes not have one label per series inpredictions.