<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/google/meridian/blob/v2.2.1/meridian/model/spec.py#L210-L275) |

Random holdout specification.

```python
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`](https://developers.google.com/meridian/reference/api/meridian/model/spec/HoldoutSpec.md.txt#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.

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `ratio` | The fraction of observations to hold out. Must be strictly between 0.0 and 1.0. |
| `seed` | Optional random seed for deterministic holdout generation. |
| `balanced` | Whether to balance the draw across time periods as well as geos, so that per-time holdout counts differ by at most one. When `False`, each geo's held-out periods are a simple random sample, independent of the other geos. Default: `False`. |

<br />

## Methods

### `__eq__`

```python
__eq__(
    other
)
```

Return self==value.

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| balanced | `False` |
| seed | `None` |

<br />