Skip to content

Commit

Permalink
resolves #796 remove dep on pygam, use IsotonicRegression (#803)
Browse files Browse the repository at this point in the history
* resolves #796 remove dep on pygam, use IsotonicRegression
* restrict propensity scores to (0,1); (0+2eps,1-2eps)
* linted

---------

Co-authored-by: Roland Stevenson <[email protected]>
  • Loading branch information
ras44 and rolandrmgservices authored Feb 7, 2025
1 parent 27990a0 commit 22b13c2
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 22b13c2

Please sign in to comment.