Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #796 remove dep on pygam, use IsotonicRegression #803

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions causalml/propensity.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABCMeta, abstractmethod
import logging
import numpy as np
from pygam import LogisticGAM, s
from sklearn.metrics import roc_auc_score as auc
from sklearn.linear_model import LogisticRegressionCV
from sklearn.model_selection import StratifiedKFold, train_test_split
from sklearn.isotonic import IsotonicRegression
import xgboost as xgb


Expand Down Expand Up @@ -179,9 +179,9 @@ def predict(self, X):


def calibrate(ps, treatment):
"""Calibrate propensity scores with logistic GAM.
"""Calibrate propensity scores with IsotonicRegression.

Ref: https://pygam.readthedocs.io/en/latest/api/logisticgam.html
Ref: https://scikit-learn.org/stable/modules/isotonic.html

Args:
ps (numpy.array): a propensity score vector
Expand All @@ -191,9 +191,11 @@ def calibrate(ps, treatment):
(numpy.array): a calibrated propensity score vector
"""

gam = LogisticGAM(s(0)).fit(ps, treatment)
two_eps = 2.0 * np.finfo(float).eps
pm_ir = IsotonicRegression(out_of_bounds="clip", y_min=two_eps, y_max=1.0 - two_eps)
ps_ir = pm_ir.fit_transform(ps, treatment)

return gam.predict_proba(ps)
return ps_ir


def compute_propensity_score(
Expand Down
Loading