Skip to content

Model

polars_ts.bayesian_var.model

Bayesian Vector Autoregression (BVAR) model class and helpers.

BayesianVAR

Bayesian Vector Autoregression forecaster.

Parameters

target_cols Column names to model jointly (>= 2). p Number of lags. prior Prior type: "minnesota" or "normal_wishart". inference Inference method: "analytical" (conjugate posterior) or "gibbs" (Gibbs sampling). minnesota_prior Minnesota prior settings. Used when prior="minnesota". nw_prior Normal-Wishart prior settings. Used when prior="normal_wishart". coverage Credible interval coverage level (default 0.9). n_samples Number of Gibbs samples (after burn-in). burn_in Number of Gibbs burn-in samples. seed Random seed. time_col Column with timestamps.

fit(df, id_col=None)

Fit the Bayesian VAR model.

_fit_single(df, gid)

Fit BVAR on a single group/series.

predict(horizon, id_col=None)

Generate multi-step forecasts with credible intervals.

_forecast_single(result, horizon, alpha_half)

Forecast from a single fitted result.

irf(steps=20, shock_size=1.0, gid=None)

Compute impulse response functions with credible bands.

_compute_irf(B, k, p, steps, shock_size) staticmethod

Compute orthogonalized IRF from coefficient matrix.

_build_var_matrices(data, p)

Build design matrix X and response Y for VAR(p).

Parameters

data Array of shape (n, k) with the multivariate time series. p Number of lags.

Returns

X Design matrix, shape (n-p, k*p+1) (includes intercept). Y Response matrix, shape (n-p, k).

bayesian_var(df, target_cols, horizon, p=1, prior='minnesota', inference='analytical', minnesota_prior=None, nw_prior=None, coverage=0.9, n_samples=1000, burn_in=500, seed=42, time_col='ds', id_col=None)

Bayesian VAR convenience function.