$ show py-why/EconML
EconML is a Python library for estimating heterogeneous treatment effects (CATE) from observational and experimental data using machine learning. It implements state-of-the-art causal inference methods including Double/Debiased Machine Learning (DML), Generalized Random Forests (GRF), Orthogonal Random Forests, Doubly Robust Learners, Instrumental Variable estimators (DMLIV, DRIV, OrthoIV), and Meta-Learners (S, T, X, DA). The library provides a unified scikit-learn-compatible API across all estimators with fit, effect, marginal_effect, and inference methods (confidence intervals, p-values). It includes advanced features such as cross-fitting, sample weights, missing data support, federated learning, sensitivity analysis, and model selection via RScorer. The repository also contains extensive documentation, notebooks, Monte Carlo tests, and a Cython-optimized tree implementation for performance.
The LLM identified 4 files worth highlighting for reuse:
Centralized module that handles scikit-learn API changes across versions. Provides version-conditional shims for deprecated or moved symbols (e.g., one_hot_encoder, _check_feature_names_in, make_column_selector). This pattern allows the library to support multiple sklearn versions without scattering version checks throughout the codebase. Reusable as a template for any library maintaining backward compatibility with sklearn.
Implements BootstrapEstimator, a generic wrapper that adds bootstrap confidence intervals to any estimator. Supports stratified resampling, parallel execution, and multiple interval types (percentile, pivot, normal). The class is self-contained and can be extracted to add bootstrap inference to arbitrary models in new projects.
Contains custom linear models like WeightedLasso, WeightedLassoCV, DebiasedLasso, and StatsModelsLinearRegression. These extend scikit-learn's linear models with sample weight support and debiased inference for high-dimensional settings. The WeightedModelMixin pattern for adding weights to any linear model is particularly reusable.
Defines BaseTree, a base class for custom decision trees with honest splitting (train/validation split within nodes), min_balancedness_tol, and min_var_leaf. This is the foundation for the Cython-optimized tree implementations used in forests. The pattern of separating tree structure from splitting criteria enables easy extension to new causal splitting rules.