How py-why/econml works
Project Type and Purpose
• This is an open-source Python library (EconML) for estimating heterogeneous treatment effects via machine learning.
• It provides a unified API to implement causal inference methods (DML, DR, IV, forests, metalearners, policy learning, DeepIV, interpretability, inference).
• Designed as a backbone for other Python applications and notebooks to import and use.
File Structure Analysis
• Top-level:
• .github/workflows/ – CI/CD pipelines (linting, testing, publishing docs & package)
• econml/ – main Python package, subdivided into modules and sub-packages:
– _cate_estimator.py, _ensemble/, _ortho_learner.py, _shap.py, _tree_exporter.py, etc.
– Functional sub-packages: dml, dr, iv, metalearners, orf, panel, policy, score, inference, cate_interpreter, data, grf, sklearn_extensions, tree, validate.
• doc/ – Sphinx documentation source and user guide PDF.
• notebooks/, monte_carlo_tests/, prototypes/ – example workflows, experiments, demos.
• econml/tests/ – pytest-based unit and integration tests mirroring the package structure.
• Config & packaging: pyproject.toml, setup.py, .pre-commit-config.yaml, .gitignore.
README Insights
• Emphasizes package capabilities, target audience (econometrics + ML practitioners), and supported methods.
• Usage examples for each method category highlight the core API (fit, effect, effect_interval, summaries, interpret).
• Developer instructions: testing, building docs with Sphinx, release process (GitHub Actions).
a. Main Components
• User/Application Layer
• Python client code / Jupyter notebooks that import EconML estimators.
• EconML Core
• Packages: dml, dr, iv, metalearners, orf, panel, policy, inference, cate_interpreter, data, utilities, tree, sklearn_extensions, validate.
• External Dependencies
• Core: numpy, scipy, scikit-learn, pandas, joblib
• Optional: keras/tensorflow (DeepIV), xgboost (notebooks), graphviz (docs), shap, matplotlib.
• Development & CI/CD
• GitHub Actions workflows: ci.yml, publish-package.yml, publish-documentation.yml, doc generation script.
• Pre-commit, pytest, Sphinx.
• Distribution
• PyPI package, documentation website hosted via GitHub Pages/Azure.
b. Relationships and Interactions
• EconML Core modules import and coordinate with one another (e.g., dml uses inference, data, utilities).
• Core modules call into external dependencies for numeric computation, ML modeling, and graphing.
• Development pipelines trigger on commits/tags: lint & test → build & publish package → build & publish docs.
• Notebooks and prototypes consume the installed package to demonstrate functionality.
c. Architectural Patterns and Principles
• Modular layering: each causal method category in its own sub-package.
• Shared utilities: cross-cutting concerns (data generation, model selection, parallelization).
• Cross-fitting & dependency injection: estimators accept arbitrary scikit-learn estimators.
• Separation of concerns: core logic vs. examples vs. docs vs. tests.
d. Key Technologies, Frameworks, Libraries
• Language: Python 3.7+
• Testing: pytest, unittest
• Documentation: Sphinx, reStructuredText, Graphviz
• CI/CD: GitHub Actions
• ML: scikit-learn, numpy, scipy, pandas, keras
• Packaging: setuptools, wheel, PyPI