cleverly.PlannedFits#

class cleverly.PlannedFits(rows: tuple[PlannedFitRow, ...], candidates: tuple[tuple[str, int, int | None], ...] = (), multipliers: tuple[tuple[str, int], ...] = (), searches: tuple[tuple[str, int, bool, int], ...] = (), folds: Literal['realized', 'outer realized', 'one draw'] = 'realized', unpreviewed: tuple[str, ...] = (), notes: tuple[str, ...] = ())[source]#

The learner fits an estimate call would make, counted before any learner runs.

cleverly.IdentifiedEffect.planned_fits() returns one. It holds names and counts, no learner objects.

Parameters:
rowstuple of PlannedFitRow

One row per nuisance role and scope.

candidatestuple of tuple

(name, candidate_fits, internal_cv) per base estimator, across rows. internal_cv is the fold count of a candidate that cross-validates internally, read from its final step with cv=None read as scikit-learn’s 5, else None.

multiplierstuple of tuple

(name, value) per factor the counts multiply by, such as outer folds, repeats and bootstrap replicates.

searchestuple of tuple

(name, maximum, stops_early, learner_fits) per candidate search a method runs. Empty for a method that searches nothing.

folds{“realized”, “outer realized”, “one draw”}

"realized" when an integer random_state fixes every draw the counts read, so they are the folds estimate uses. "outer realized" when a split plan fixes the outer folds and the seeds below them are drawn fresh. "one draw" when the folds are drawn fresh on every fit, so fold-dependent counts describe one draw.

unpreviewedtuple of str

The checks estimate still runs after the point where the count stops, by qualified function name, such as "fit_tuner" or "Piece.__post_init__": the fit of a tuned cap whose boundary is a learner, and each check that can refuse the tuned values. Empty for most calls.

notestuple of str

Plain sentences about what the counts include and leave out.

Attributes:
total_fitsint

The attempted top-level fits over every row, an upper bound when not exact.

total_candidate_fitsint

The attempted base-estimator fits over every row.

exactbool

Whether every row is exact, so the totals are the fits estimate makes.

min_fitsint

The fewest top-level fits: an exact row’s count plus an upper row’s minimum.

See also

cleverly.IdentifiedEffect.planned_fits

What returns this record.

Examples

>>> from sklearn.linear_model import LinearRegression, LogisticRegression
>>> from cleverly import ATE, CausalStudy, PointTreatment
>>> from cleverly.datasets import make_linear_ate
>>> frame, _ = make_linear_ate(n=200, seed=1)
>>> study = CausalStudy(
...     frame,
...     design=PointTreatment(
...         outcome="Y", treatment="A", adjustment=("W1", "W2", "W3", "W4")
...     ),
... )
>>> plan = study.planned_fits(
...     ATE(),
...     outcome_learner=LinearRegression(),
...     treatment_learner=LogisticRegression(),
...     n_folds=5,
...     random_state=0,
...     q_bounds=(-20.0, 20.0),
... )
>>> plan.total_fits, plan.exact
(10, True)

Methods#

PlannedFits.summary(*, detail: Literal['short', 'full'] = 'short') → Summary[source]#

Return the printed table of the planned fits.

Parameters:
detail{“short”, “full”}, default “short”

"full" adds the multipliers, the notes and any check left to the fit.

Returns:
Summary

A str whose text is the printed table; a notebook renders it as HTML.

PlannedFits.to_frame(backend: str | None = None) → Any[source]#

Return one row per nuisance role and scope.

Parameters:
backend{“pandas”, “polars”, “pyarrow”} or None, default=None

Dataframe backend to return. None uses pandas when installed, then the first available backend.

Returns:
dataframe

Columns role, scope, learner, fits, candidate_fits, bound, min_fits and why.

Attributes#

PlannedFits.candidates: tuple[tuple[str, int, int | None], ...] = ()#
PlannedFits.exact#

Whether every row is exact, so the totals are the fits estimate makes.

PlannedFits.folds: Literal['realized', 'outer realized', 'one draw'] = 'realized'#
PlannedFits.min_fits#

The fewest top-level fits: an exact row’s count plus an upper row’s minimum.

PlannedFits.multipliers: tuple[tuple[str, int], ...] = ()#
PlannedFits.notes: tuple[str, ...] = ()#
PlannedFits.searches: tuple[tuple[str, int, bool, int], ...] = ()#
PlannedFits.total_candidate_fits#

The attempted base-estimator fits over every row.

PlannedFits.total_fits#

The attempted top-level fits over every row, an upper bound when not exact.

PlannedFits.unpreviewed: tuple[str, ...] = ()#
PlannedFits.rows: tuple[PlannedFitRow, ...]#