metacausal.aggregation.TrainAvgSplit

class metacausal.aggregation.TrainAvgSplit(avg_frac=0.25, stratify=True)[source]

Bases: object

Simple train / averaging-set split.

Holds out a fraction of observations as the “averaging set” where ensemble weights are optimized. Component models are trained on the remainder.

Parameters:
  • avg_frac (float) – Fraction of observations held out for weight optimization. Must be in (0, 1). Typical values: 0.2–0.3.

  • stratify (bool) – If True, stratify the split on treatment assignment T. Subject to the same discrete-T requirement as CrossFitSplit.

Examples

>>> import numpy as np
>>> from metacausal.aggregation import TrainAvgSplit
>>> T = np.array([0, 1] * 10)
>>> fold_spec = TrainAvgSplit(avg_frac=0.3).split(T, random_state=0)
>>> fold_spec.n_folds
1
>>> len(fold_spec.train_indices[0]), len(fold_spec.test_indices[0])
(14, 6)

Methods

__init__

split

Partition n observations into training and averaging sets.

Attributes

Details

split(T, random_state=None)[source]

Partition n observations into training and averaging sets.

Parameters:
  • T (array of shape (n,)) – Treatment assignments. Used for stratification when stratify=True.

  • random_state (int or None) – Random seed for reproducibility.

Returns:

FoldSpec with n_folds=1. – train_indices[0] — indices for fitting component models. test_indices[0] — indices for optimizing ensemble weights.

Return type:

FoldSpec

avg_frac: float = 0.25
stratify: bool = True