bayespecon.diagnostics.spatial_kfold

bayespecon.diagnostics.spatial_kfold(model, *, fold_ids=None, n_blocks=10, geometry=None, draws=400, tune=400, chains=2, random_seed=0, progressbar=False, **fit_kwargs)[source]

Spatial block cross-validation for a fitted Bayesian spatial model.

Refits the model on each training fold and evaluates the conditional Gaussian predictive density of the held-out fold under the full-data joint implied by the model.

Parameters:
model : SpatialModel

A model from bayespecon.models. The model must have been constructed (its _X, _y and _W_sparse will be used for prediction); it does not need to be fit, since fold-specific refits are performed internally.

fold_ids : np.ndarray, optional

Integer fold assignment per observation, shape (n,). When supplied, n_blocks and geometry are ignored.

n_blocks : int, default 10

Number of spatial blocks for the KMeans fallback when fold_ids is not provided.

geometry : geopandas.GeoSeries, optional

Geometry used by the KMeans fallback to cluster centroids. Required when fold_ids is None.

draws=400

Forwarded to SpatialModel.fit() for each per-fold refit. Defaults are deliberately modest to keep CV affordable.

tune=400

Forwarded to SpatialModel.fit() for each per-fold refit. Defaults are deliberately modest to keep CV affordable.

chains=2

Forwarded to SpatialModel.fit() for each per-fold refit. Defaults are deliberately modest to keep CV affordable.

random_seed=0

Forwarded to SpatialModel.fit() for each per-fold refit. Defaults are deliberately modest to keep CV affordable.

progressbar=False

Forwarded to SpatialModel.fit() for each per-fold refit. Defaults are deliberately modest to keep CV affordable.

**fit_kwargs

Extra keyword arguments forwarded to SpatialModel.fit().

Return type:

SpatialCVResult

Notes

Computation is \(O(K \cdot G \cdot \text{nnz}(W))\) per fold plus the cost of refitting; spatial folds are typically a handful (e.g. n_blocks=5–10). For OLS/SLX the predictive collapses to the standard independent Gaussian and the per-fold cost is \(O(G \cdot n_{\text{test}} \cdot k)\).