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.DatasetEither 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