Skip to content

Commit

Permalink
resolves #796 remove dep on pygam, use IsotonicRegression
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandrmgservices committed Nov 9, 2024
1 parent a52eef4 commit 24d77d7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 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,10 @@ def calibrate(ps, treatment):
(numpy.array): a calibrated propensity score vector
"""

gam = LogisticGAM(s(0)).fit(ps, treatment)
pm_ir = IsotonicRegression(out_of_bounds="clip")
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 24d77d7

Please sign in to comment.