--- title: Metalearner Propensity keywords: fastai sidebar: home_sidebar summary: "Metalearner Propensity" description: "Metalearner Propensity" nb_path: "nbs/05h_meta.propensity.ipynb" ---
{% raw %}
{% endraw %} {% raw %}

class PropensityModel[source]

PropensityModel(clip_bounds=(0.001, 0.999), **model_kwargs)

{% endraw %} {% raw %}

class LogisticRegressionPropensityModel[source]

LogisticRegressionPropensityModel(clip_bounds=(0.001, 0.999), **model_kwargs) :: PropensityModel

Propensity regression model based on the LogisticRegression algorithm.

{% endraw %} {% raw %}

class ElasticNetPropensityModel[source]

ElasticNetPropensityModel(clip_bounds=(0.001, 0.999), **model_kwargs) :: LogisticRegressionPropensityModel

Propensity regression model based on the LogisticRegression algorithm.

{% endraw %} {% raw %}

class GradientBoostedPropensityModel[source]

GradientBoostedPropensityModel(early_stop=False, clip_bounds=(0.001, 0.999), **model_kwargs) :: PropensityModel

Gradient boosted propensity score model with optional early stopping.

Notes

Please see the xgboost documentation for more information on gradient boosting tuning parameters: https://xgboost.readthedocs.io/en/latest/python/python_api.html

{% endraw %} {% raw %}

calibrate[source]

calibrate(ps, treatment)

Calibrate propensity scores with logistic GAM.

Ref: https://pygam.readthedocs.io/en/latest/api/logisticgam.html

Args: ps (numpy.array): a propensity score vector treatment (numpy.array): a binary treatment vector (0: control, 1: treated)

Returns: (numpy.array): a calibrated propensity score vector

{% endraw %} {% raw %}

compute_propensity_score[source]

compute_propensity_score(X, treatment, p_model=None, X_pred=None, treatment_pred=None, calibrate_p=True)

Generate propensity score if user didn't provide

Args: X (np.matrix): features for training treatment (np.array or pd.Series): a treatment vector for training p_model (propensity model object, optional): ElasticNetPropensityModel (default) / GradientBoostedPropensityModel X_pred (np.matrix, optional): features for prediction treatment_pred (np.array or pd.Series, optional): a treatment vector for prediciton calibrate_p (bool, optional): whether calibrate the propensity score

Returns: (tuple)

    - p (numpy.ndarray): propensity score
    - p_model (PropensityModel): a trained PropensityModel object
{% endraw %} {% raw %}
{% endraw %}