https://github.com/riskified/ps-matching
python class to perform propensity score matching
https://github.com/riskified/ps-matching
Last synced: 4 months ago
JSON representation
python class to perform propensity score matching
- Host: GitHub
- URL: https://github.com/riskified/ps-matching
- Owner: Riskified
- Created: 2023-01-22T11:17:24.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-02-10T19:47:03.000Z (over 1 year ago)
- Last Synced: 2025-05-20T15:12:41.832Z (about 1 year ago)
- Language: Jupyter Notebook
- Homepage:
- Size: 949 KB
- Stars: 7
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# ps-matching
python class to perform propensity score matching
# How to Use the ps-matching code:
## Set global variables:
```
PS_GROUP = 'treatment' # set the group variable (treatment/control)
TARGET = 'target' # set the target variable, the outcome of interest
FILE_PATH = 'data/df.csv' # dataframe contains all dependant and independent variables
```
## PrepData Class initiation:
```
data = PrepData(FILE_PATH, group=PS_GROUP, target=TARGET, index_col="id")
```
## initiate the PScorer and estimate the Propensity Score:
```
scorer = PScorer()
scorer.fit(data.input, data.group_label)
ps_scores: Series = scorer.predict(data.input)
```
## Get ROC curve to assess model fit:
```
ScorePlotter.plot_roc_curve(ps_scores, data.group_label)
```
## Initiate the ObsMatcher class, set the matching ratio and the caliper:
```
matcher = ObsMatcher(n_matches=1, caliper=0.001)
matched_index: List[int] = matcher.match_scores(ps_scores, data.group_label)
```
## Plot SMD before and after matching:
```
ScorePlotter.plot_smd_comparison(
data=data.input,
matched_index=matched_index,
treatment=data.group_label
)
```