causallib.evaluation.predictor module
Predictor classes.
Predictors generate sets of predictions for a single fold with no cross-validation or train-test logic.
- class causallib.evaluation.predictor.BasePredictor(estimator)[source]
Bases:
object
Generate predictions from estimator for evaluation (base class).
- static from_estimator(estimator: Union[causallib.estimation.base_estimator.IndividualOutcomeEstimator, causallib.estimation.base_weight.PropensityEstimator, causallib.estimation.base_weight.WeightEstimator])[source]
Select subclass based on estimator.
- Parameters
estimator (Union[IndividualOutcomeEstimator, PropensityEstimator, WeightEstimator]) – Estimator to generate evaluation predictions from.
- Returns
- the correct predictor for
the supplied estimator
- Return type
Union[PropensityPredictor, WeightPredictor, OutcomePredictor]
- class causallib.evaluation.predictor.OutcomePredictor(estimator)[source]
Bases:
causallib.evaluation.predictor.BasePredictor
Generate evaluation predictions for IndividualOutcomeEstimator models.
- Parameters
estimator (IndividualOutcomeEstimator) –
- class causallib.evaluation.predictor.PropensityPredictor(estimator)[source]
Bases:
causallib.evaluation.predictor.WeightPredictor
Generate evaluation predictions for PropensityEstimator models.
- Parameters
estimator (PropensityEstimator) –
- class causallib.evaluation.predictor.WeightPredictor(estimator)[source]
Bases:
causallib.evaluation.predictor.BasePredictor
Generate evaluation predictions for WeightEstimator models.
- Parameters
estimator (WeightEstimator) –
- causallib.evaluation.predictor.predict_cv(estimator, X, a, y, cv, refit=True, phases=('train', 'valid'))[source]
Obtain predictions on the provided data in cross-validation
- Parameters
X (pd.DataFrame) – Covariates.
a (pd.Series) – Treatment assignment.
y (pd.Series) – Outcome.
cv (list[tuples]) – list the number of folds containing tuples of indices (train_idx, validation_idx)
refit (bool) – Whether to refit the model on each fold.
phases (list[str]) – {[“train”, “valid”], [“train”], [“valid”]}. Phases names to evaluate on - train (“train”), validation (“valid”) or both. ‘train’ corresponds to cv[i][0] and ‘valid’ to cv[i][1]
- Returns
A two-tuple containing:
- predictions: dictionary with keys being the phases provided and values are
list the size of the number of folds in cv and containing the output of the estimator on that corresponding fold. For example, predictions[“valid”][3] contains the prediction of the estimator on untrained data of the third fold (i.e. validation set of the third fold)
- models: list the size of the number of folds in cv containing the fitted estimator
on the training data of that fold.
- Return type