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
estimatecall would make, counted before any learner runs.cleverly.IdentifiedEffect.planned_fits()returns one. It holds names and counts, no learner objects.- Parameters:
- rows
tupleofPlannedFitRow One row per nuisance role and scope.
- candidates
tupleoftuple (name, candidate_fits, internal_cv)per base estimator, across rows.internal_cvis the fold count of a candidate that cross-validates internally, read from its final step withcv=Noneread as scikit-learn’s 5, elseNone.- multipliers
tupleoftuple (name, value)per factor the counts multiply by, such as outer folds, repeats and bootstrap replicates.- searches
tupleoftuple (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 integerrandom_statefixes every draw the counts read, so they are the foldsestimateuses."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.- unpreviewed
tupleofstr The checks
estimatestill 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.- notes
tupleofstr Plain sentences about what the counts include and leave out.
- rows
- Attributes:
total_fitsintThe attempted top-level fits over every row, an upper bound when not
exact.total_candidate_fitsintThe attempted base-estimator fits over every row.
exactboolWhether every row is exact, so the totals are the fits
estimatemakes.min_fitsintThe fewest top-level fits: an exact row’s count plus an upper row’s minimum.
See also
cleverly.IdentifiedEffect.planned_fitsWhat 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.
- detail{“short”, “full”},
- Returns:
SummaryA
strwhose 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”}
orNone, default=None Dataframe backend to return.
Noneuses pandas when installed, then the first available backend.
- backend{“pandas”, “polars”, “pyarrow”}
- Returns:
dataframeColumns
role,scope,learner,fits,candidate_fits,bound,min_fitsandwhy.
Attributes#
- PlannedFits.exact#
Whether every row is exact, so the totals are the fits
estimatemakes.
- PlannedFits.min_fits#
The fewest top-level fits: an exact row’s count plus an upper row’s minimum.
- PlannedFits.total_candidate_fits#
The attempted base-estimator fits over every row.