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_samplesdraws from the flattened chain × draw space and returns a new Dataset with a single chain andnum_samplesdraws.- Parameters:
- dataset
xr.Dataset Dataset with
chainanddrawdimensions.- num_samples
intorNone Number of draws to keep. If
Noneor >= total available draws, returns dataset unchanged.- random_state
RandomState,Generator, orNone, optional Seed or random state for reproducibility.
- dataset
- Returns:
xr.DatasetWhen
num_samplesisNoneor >= total draws, returns dataset unchanged (preserving its original chain/draw structure). When subsampling occurs, returns a new Dataset with shape(chain=1, draw=num_samples).
Examples
>>> sub = subsample_draws(posterior, num_samples=100, random_state=42) >>> sub.sizes["draw"] 100