cleverly.CrossFitting#

class cleverly.CrossFitting(enabled: bool = True, n_folds: int = 10, learner_folds: int = 5, repeats: int = 1, stratify_by: Literal['none', 'treatment', 'treatment+outcome'] = 'none', targeting_scheme: Literal['pooled', 'fold'] = 'pooled', fold_evaluation: bool = False, split_plan: SplitPlan | None = None)[source]#

Configure outer and learner-level sample splitting.

Parameters:
enabledbool, default=True

Whether to estimate nuisances out of fold.

n_foldsint, default=10

Number of outer folds.

learner_foldsint, default=5

Inner folds used by ensemble learners.

repeatsint, default=1

Independent outer-fold assignments to combine by their median. A value above one requires enabled=True.

stratify_by{“none”, “treatment”, “treatment+outcome”}, default=”none”

Fold-stratification policy. "none" draws folds that read neither the treatment nor the outcome, and it is the only value a fit that draws a split accepts. "treatment" and "treatment+outcome" are refused with enabled=True, and refused at every setting by selector-based CollaborativeTMLEMethod fits, whose search draws selection folds without cross-fitting. In-sample outcome-adaptive fits draw no such split and accept the unused declaration. No shipped result covers a partition read off the data the fit then conditions on.

targeting_scheme{“pooled”, “fold”}, default=”pooled”

Pooled or fold-specific targeting scheme.

fold_evaluationbool, default=False

Whether to retain fold-evaluated CV-TMLE estimates.

split_planSplitPlan, optional

Reusable outer-fold assignments in repeat-major order. The plan must record how random_partition() drew each repeat, as result.split_plan from an unstratified fit does. A plan without that record is refused here.

See also

TMLEMethod

Method configuration this object is the splitting half of.

Targeting

Whether the fluctuation is pooled or fitted per fold.

SplitPlan

Reusable outer-fold assignments accepted by this configuration.

cleverly.learners.make_folds

The partition this configuration asks for.

Examples

Fewer folds, combined over three independent splits:

>>> from cleverly import CrossFitting
>>> folds = CrossFitting(n_folds=5, repeats=3)
>>> folds.n_folds, folds.repeats
(5, 3)

Turn cross-fitting off to fit every nuisance on all the rows:

>>> CrossFitting(enabled=False).enabled
False

Methods#

Attributes#

CrossFitting.enabled: bool = True#
CrossFitting.fold_evaluation: bool = False#
CrossFitting.learner_folds: int = 5#
CrossFitting.n_folds: int = 10#
CrossFitting.repeats: int = 1#
CrossFitting.split_plan: SplitPlan | None = None#
CrossFitting.stratify_by: Literal['none', 'treatment', 'treatment+outcome'] = 'none'#
CrossFitting.targeting_scheme: Literal['pooled', 'fold'] = 'pooled'#