{"id":5203,"library":"econml","title":"EconML","description":"EconML is a Python library for estimating Conditional Average Treatment Effects (CATEs) from observational or experimental data. It provides a suite of advanced machine learning methods, including Double Machine Learning (DML) and Causal Forests, to infer causal relationships and individual-level treatment effects. The current version is 0.16.0, and it maintains an active development pace with major updates and bugfix releases every few months.","status":"active","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/py-why/EconML","tags":["causal inference","machine learning","econometrics","treatment effects","causality","uplift modeling"],"install":[{"cmd":"pip install econml","lang":"bash","label":"Base installation"},{"cmd":"pip install econml[ray]  # For distributed training with Ray\npip install econml[deepiv] # For DeepIV estimator with TensorFlow/Keras\npip install econml[all] # For all optional dependencies","lang":"bash","label":"With optional dependencies"}],"dependencies":[{"reason":"Core numerical operations","package":"numpy","optional":false},{"reason":"Core numerical operations","package":"scipy","optional":false},{"reason":"Data manipulation","package":"pandas","optional":false},{"reason":"Machine learning models and utilities","package":"scikit-learn","optional":false},{"reason":"Gradient boosting models","package":"lightgbm","optional":false},{"reason":"Feature importance (SHAP values)","package":"shap","optional":false},{"reason":"Causal inference pipeline integration","package":"dowhy","optional":true},{"reason":"Required for DeepIV estimator","package":"tensorflow","optional":true},{"reason":"Required for DeepIV estimator","package":"keras","optional":true},{"reason":"Required for distributed training/scaling","package":"ray","optional":true}],"imports":[{"note":"CausalForestDML, like other DML estimators, resides in `econml.dml`.","wrong":"from econml.dr import CausalForestDML","symbol":"CausalForestDML","correct":"from econml.dml import CausalForestDML"},{"note":"LinearDML is part of the Double Machine Learning (DML) module.","symbol":"LinearDML","correct":"from econml.dml import LinearDML"},{"note":"As of v0.14.0, DynamicDML was moved to the `econml.panel` subpackage.","wrong":"from econml.dml import DynamicDML","symbol":"DynamicDML","correct":"from econml.panel import DynamicDML"}],"quickstart":{"code":"import numpy as np\nimport pandas as pd\nfrom econml.dml import CausalForestDML\nfrom sklearn.ensemble import RandomForestRegressor, RandomForestClassifier\n\n# Simulate data\nnp.random.seed(42)\nn_samples = 1000\nW = np.random.normal(0, 1, size=(n_samples, 3)) # Confounders\nX = np.random.normal(0, 1, size=(n_samples, 2)) # Features for heterogeneity\nT = (W[:, 0] + W[:, 1] + np.random.normal(0, 1, n_samples) > 0).astype(float) # Treatment\nY = W[:, 0] + W[:, 2] + T * (X[:, 0] + np.random.normal(0, 0.1, n_samples)) + np.random.normal(0, 1, n_samples) # Outcome\n\n# Initialize and fit the CausalForestDML model\nest = CausalForestDML(\n    model_y=RandomForestRegressor(min_samples_leaf=5, n_estimators=100, random_state=42),\n    model_t=RandomForestClassifier(min_samples_leaf=5, n_estimators=100, random_state=42),\n    cv=5,\n    random_state=42\n)\nest.fit(Y, T, X=X, W=W)\n\n# Estimate CATE for new data (or original X)\nX_test = np.array([[0.5, 0.5], [-0.5, -0.5]])\ncate_estimates = est.effect(X_test)\nprint(f\"CATE estimates for X_test: {cate_estimates}\")\n\n# Expected output: CATE estimates for X_test: [0.67204641 0.44976767]","lang":"python","description":"This quickstart demonstrates how to use `CausalForestDML` to estimate Conditional Average Treatment Effects (CATEs) using synthetic data. It involves defining confounders (W), features for heterogeneity (X), treatment (T), and outcome (Y), then fitting the model and predicting CATEs for new feature values. `RandomForestRegressor` and `RandomForestClassifier` are used as base learners for Y and T models respectively."},"warnings":[{"fix":"Update import statements from `from econml.dml import DynamicDML` to `from econml.panel import DynamicDML`.","message":"The `DynamicDML` estimator was moved from `econml.dml` to `econml.panel`. Direct imports from the old path will raise an `ImportError`.","severity":"breaking","affected_versions":">=0.14.0"},{"fix":"Explicitly set the `alpha` parameter in `effect_interval` or similar methods if you rely on a specific alpha value or wish to restore prior behavior.","message":"The default `alpha` value for confidence intervals in methods like `effect_interval` changed from `None` (user-defined or estimator-specific) to `0.05` (representing 95% confidence).","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Ensure your installed `shap` version is within the compatible range. Downgrade `shap` to `<0.44.0` if you encounter issues (`pip install 'shap<0.44.0'`).","message":"EconML v0.16.0 requires `shap` versions `>=0.40.0` and `<0.44.0`. Using `shap` version 0.44.0 or higher will lead to installation conflicts or runtime errors when calling `shap_values`.","severity":"gotcha","affected_versions":"0.16.0"},{"fix":"Install `econml` with the `[deepiv]` extra (`pip install econml[deepiv]`) to ensure the correct `tensorflow`/`keras` versions are pulled, or manually manage these dependencies carefully to avoid conflicts with other parts of your environment.","message":"The `deepiv` module, containing the `DeepIV` estimator, requires `tensorflow` and `keras` to be installed separately. These libraries can have strict Python and other dependency version requirements that may cause conflicts.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `econml` with the `[ray]` extra (`pip install econml[ray]`) to enable distributed training capabilities.","message":"Distributed training features (e.g., for scaling `OrthoLearner`s) rely on the `ray` library, which is an optional dependency and not installed by default.","severity":"gotcha","affected_versions":">=0.15.0"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}