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_folds
int, default=10 Number of outer folds.
- learner_folds
int, default=5 Inner folds used by ensemble learners.
- repeats
int, 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 withenabled=True, and refused at every setting by selector-basedCollaborativeTMLEMethodfits, 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_plan
SplitPlan,optional Reusable outer-fold assignments in repeat-major order. The plan must record how
random_partition()drew each repeat, asresult.split_planfrom an unstratified fit does. A plan without that record is refused here.
See also
TMLEMethodMethod configuration this object is the splitting half of.
TargetingWhether the fluctuation is pooled or fitted per fold.
SplitPlanReusable outer-fold assignments accepted by this configuration.
cleverly.learners.make_foldsThe 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