Skip to main content

pycausalmatch

pycausalmatch is a Python library for causal inference integrated with the process of selecting suitable control groups

(I plan to develop this as one would a causal inference project for Big Data with the intent of eventually deploying pipelines)

Description

The functionality that has been implemented so far is essentially a Python translation of the features available in the R library: https://github.com/klarsen1/MarketMatching (v.1.1.7 - as of Dec 2020), which combines 2 packages: https://github.com/WillianFuks/tfcausalimpact and https://github.com/DynamicTimeWarping/dtw-python

(I switched to tfcausalimpact in v0.0.4, from pycausalimpact, which was available at https://github.com/dafiti/causalimpact, but has now been removed)

The DTW package is used for selection of most suitable control groups.

The R library has a detailed README.

The causal impact from this Python version matches the impact for the test market ('CPH') in the example in the R library, as shown in the plots in the starter_example notebook.

This is still an alpha release - I'm in the process of adding more features, and fixing all the bugs soon!

Installation

Use the package manager pip to install pycausalmatch.

pip install pycausalmatch

Usage

from pycausalmatch import R_MarketMatching as rmm

rmm.best_matches(**kwargs) # returns
rmm.inference(**kwargs) # returns

This package has only been tested for a single test market (I will test it for multiple test markets soon).

Example Use case

I've added an example on the causal impact of Prop 99 in California in the notebook prop_99_example under the notebooks/examples folder. I will keep updating this example as I develop the library further.

TODOs

  • Improve README!

  • Add more examples (Prop 99 - CA)

  • add tests, logging ...

  • add statistical inference

  • use software project structure template

  • Integrate into an MLOps workflow

  • Add parallel execution (I plan to use Bodo)

  • Add Streamlit and Dash app

  • switch to https://github.com/WillianFuks/tfcausalimpact

  • add remaining functionality of the R package

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project Organization (partially implemented)


├── LICENSE
├── Makefile           <- Makefile with commands like `make data` or `make train`
├── README.md          <- The top-level README for developers using this project.
├── data
│   ├── external       <- Data from third party sources.
│   ├── interim        <- Intermediate data that has been transformed.
│   ├── processed      <- The final, canonical data sets for modeling.
│   └── raw            <- The original, immutable data dump.
│
├── docs               <- A default Sphinx project; see sphinx-doc.org for details
│
├── models             <- Trained and serialized models, model predictions, or model summaries
│
├── notebooks          <- Jupyter notebooks. Naming convention is a number (for ordering),
│                         the creator's initials, and a short `-` delimited description, e.g.
│                         `1.0-jqp-initial-data-exploration`.
│
├── references         <- Data dictionaries, manuals, and all other explanatory materials.
│
├── reports            <- Generated analysis as HTML, PDF, LaTeX, etc.
│   └── figures        <- Generated graphics and figures to be used in reporting
│
├── requirements.txt   <- The requirements file for reproducing the analysis environment, e.g.
│                         generated with `pip freeze > requirements.txt`
│
├── setup.py           <- makes project pip installable (pip install -e .) so src can be imported
├── src                <- Source code for use in this project.
│   ├── __init__.py    <- Makes src a Python module
│   │
│   ├── data           <- Scripts to download or generate data
│   │   └── make_dataset.py
│   │
│   ├── features       <- Scripts to turn raw data into features for modeling
│   │   └── build_features.py
│   │
│   ├── models         <- Scripts to train models and then use trained models to make
│   │   │                 predictions
│   │   ├── predict_model.py
│   │   └── train_model.py
│   │
│   └── visualization  <- Scripts to create exploratory and results oriented visualizations
│       └── visualize.py
│
└── tox.ini            <- tox file with settings for running tox; see tox.readthedocs.io

Project based on the cookiecutter data science project template. #cookiecutterdatascience

Metadata

Release files for pycausalmatch 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycausalmatch 0.0.4
File Size Uploaded Provenance Actions
pycausalmatch-0.0.4.tar.gz 12.8 kB Without provenance Details for pycausalmatch-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycausalmatch 0.0.4
File Interpreter ABI Platform Actions
pycausalmatch-0.0.4-py3-none-any.whl Python 3 none any Details for pycausalmatch-0.0.4-py3-none-any.whl

Total release size: 25.3 kB

Release files / pycausalmatch-0.0.4.tar.gz

Download URL pycausalmatch-0.0.4.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b49162eaec9c2165cede4041486ebd28d0659d400f54817979e0989cc42baafc
BLAKE2b-256 checksum
How to use checksums
d353f92a3af9e3cf629832792704266531720c8ac8e925732d51f10a9ae5c8f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

Release files / pycausalmatch-0.0.4-py3-none-any.whl

Download URL pycausalmatch-0.0.4-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bd5327a63ced9f78d919e9c76840b0344ce4ee0bb41ea87fd4d1543523b8804
BLAKE2b-256 checksum
How to use checksums
f38571b506f609a96face77babd1cc5d492b5d3c2d5010f73942559c4c440913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

Security for pycausalmatch 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page