View source on GitHub
|
Random holdout specification.
meridian.model.spec.RandomHoldoutSpec(
ratio: float, seed: (int | None) = None, *, balanced: bool = False
)
This specification is input only: it declares the intent to hold out a
random subset of observations, not the subset itself. The framework draws the
random sample exactly once, when the model is compiled against its input
data, producing a holdout mask over (n_geos, n_times) that becomes part of
the model's state. All downstream computation reads that resolved holdout,
never this specification.
The draw is stratified by geo: every geo holds out the same number of time
periods, round(ratio * n_times), sampled independently per geo by default.
With balanced=True the draw is additionally balanced across time periods,
so that the number of held-out observations per time period differs by at
most one. The per-time counts can differ by one because the total number of
held-out observations is not necessarily a multiple of n_times.
Both this specification and the resolved draw are serialized: the former as
provenance recording how the holdout was requested, the latter as the
authoritative record of what was actually held out. The resolved draw is
stored declaratively in HoldoutSpec.resolved, as the geos and date ranges
that were selected, rather than as a raw mask. On deserialization it always
takes precedence and is never re-drawn, because seed alone does not
reproduce a draw across computational backends (TensorFlow vs. JAX),
library versions, or different input data row/coordinate orderings (since the
PRNG stream is consumed in the order geos appear in input_data.geo).
If a serialized model carries only this specification and no resolved draw, the draw is performed on load and a warning is emitted. The resulting holdout will not match the one used during the original fit. Such a model remains valid for inference, since the holdout does not participate in inference, but its train/test predictive accuracy metrics are not meaningful.
Methods
__eq__
__eq__(
other
)
Return self==value.
Class Variables | |
|---|---|
| balanced |
False
|
| seed |
None
|
View source on GitHub