causallib.model_selection.causalize_searcher#

causalize_searcher(searcher_type)[source]#

wraps a hyperparameter search algorithm (like sklearn’s GridSearchCV) with a causallib model interface.

Parameters:

searcher_type (Type[BaseSearchCV]) – A class of hyperparameter search algorithm (e.g., sklearn’s GridSearchCV)

Returns:

a class definition of the provided searcher

with a causallib fit(X, a, y) interface and the underlying estimator capabilities.

Return type:

searcher(searcher_type)

Examples

>>> from sklearn.model_selection import GridSearchCV
>>> from sklearn.linear_model import LogisticRegression
>>> from causallib.estimation import IPW
>>> from causallib.metrics import get_scorer
>>> from causallib.datasets import load_nhefs
>>> data = load_nhefs()
>>> CausalGridSearchCV = causalize_searcher(GridSearchCV)
>>> model = IPW(LogisticRegression())
>>> scorer = get_scorer("weighted_roc_auc_error")
>>> param_grid = dict(clip_min=[0.2, 0.3])
>>> grid_model = CausalGridSearchCV(model, param_grid=param_grid, scoring=scorer)  # GridSearchCV parameters
>>> grid_model.fit(data.X, data.a, data.y)  # causallib interface
>>> grid_model.estimate_population_outcome(data.X, data.a, data.y)
>>> grid_model.compute_propensity(data.X, data.a)  # IPW capabilities