subsample_draws#

pymc_marketing.data.idata.utils.subsample_draws(dataset, *, num_samples, random_state=None)[source]#

Subsample draws from a Dataset with chain and draw dimensions.

Randomly selects num_samples draws from the flattened chain × draw space and returns a new Dataset with a single chain and num_samples draws.

Parameters:
datasetxr.Dataset

Dataset with chain and draw dimensions.

num_samplesint or None

Number of draws to keep. If None or >= total available draws, returns dataset unchanged.

random_stateRandomState, Generator, or None, optional

Seed or random state for reproducibility.

Returns:
xr.Dataset

Either the original dataset (when no subsampling is needed) or a new Dataset whose chain/draw dimensions have shape (1, num_samples).

Examples

>>> sub = subsample_draws(posterior, num_samples=100, random_state=42)
>>> sub.sizes["draw"]
100