cleverly.variable_importance_plan#
- cleverly.variable_importance_plan(data: Any, *, outcome: str, candidates: Sequence[str], covariates: Sequence[str], estimand: str = 'ate', estimator: TMLE | None = None, adjust_for_other_candidates: bool = True, delta: str | None = None, weights: str | None = None, weights_type: str = 'probability', weights_estimated: bool = False, id: str | None = None) PlannedFits[source]#
Count the model fits
variable_importance()would make, without fitting any.Takes the arguments of
variable_importance()exceptkeep_fits, which does not change the fits. It runs the same refusals in the same order, prepares each candidate’s data as the run does, and counts the fits of each candidate’s own TMLE fit.- Parameters:
- data
DataFrame The original pandas or polars dataframe.
- outcome
str Outcome column.
- candidatessequence
ofstr Candidate exposures, each fitted in turn as the treatment.
- covariatessequence
ofstr Baseline covariates.
- estimand
str Target parameter stem fitted for each candidate.
- estimator
TMLEorNone Template estimator;
NoneusesTMLE(estimands=estimand).- adjust_for_other_candidatesbool
Whether the other candidates join each candidate’s adjustment set.
- delta
strorNone Outcome-observation indicator column.
- weights
strorNone Probability-weight column.
- weights_type{“probability”}
Interpretation of
weights.- weights_estimatedbool
Whether the supplied weights were estimated from these data.
- id
strorNone Independent-cluster identifier used for variance estimation.
- data
- Returns:
PlannedFitsOne row per model, scope and candidate. Each scope ends with the candidate it belongs to, and the multiplier
"candidate exposures"gives their number. A multiplier whose value differs between candidates, such as the number of arms, is left out and named in a note.
See also
variable_importanceThe fits this counts.
cleverly.PlannedFitsThe record returned.
cleverly.IdentifiedEffect.planned_fitsThe same preview for one estimate.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn.linear_model import LinearRegression, LogisticRegression >>> from cleverly import variable_importance_plan >>> from cleverly.estimators import TMLE >>> rng = np.random.default_rng(0) >>> frame = pd.DataFrame( ... { ... "W": rng.normal(size=200), ... "X1": rng.integers(0, 2, 200), ... "X2": rng.integers(0, 2, 200), ... } ... ) >>> frame["Y"] = frame["X1"] + frame["W"] + rng.normal(size=200) >>> plan = variable_importance_plan( ... frame, ... outcome="Y", ... candidates=["X1", "X2"], ... covariates=["W"], ... estimator=TMLE( ... outcome_learner=LinearRegression(), ... treatment_learner=LogisticRegression(), ... cross_fit=False, ... random_state=0, ... ), ... ) >>> plan.total_fits, plan.exact (4, True)