{"id":23398,"library":"causalml","title":"CausalML","description":"CausalML is a Python package for uplift modeling and causal inference with machine learning algorithms. It provides a variety of methods for causal inference in both experimental and observational settings, including meta-learners (S-Learner, T-Learner, X-Learner, R-Learner), tree-based methods (Causal Forest, Uplift Random Forest), and deep learning models. Current version: 0.16.0. Release cadence: irregular, with major updates approximately annually.","status":"active","version":"0.16.0","language":"python","source_language":"en","source_url":"https://github.com/uber/causalml","tags":["causal-inference","uplift-modeling","machine-learning","python"],"install":[{"cmd":"pip install causalml","lang":"bash","label":"Install from PyPI"},{"cmd":"pip install causalml[all]","lang":"bash","label":"Install with all dependencies (TensorFlow, PySpark, etc.)"}],"dependencies":[{"reason":"Core dependency for model training and evaluation","package":"scikit-learn","optional":false},{"reason":"Required for gradient-boosted tree models","package":"xgboost","optional":false},{"reason":"Alternative boosting backend","package":"lightgbm","optional":true},{"reason":"Required for neural network models (CEVAE, DragonNet)","package":"tensorflow","optional":true}],"imports":[{"note":"Since v0.12, meta-learners moved to causalml.inference.meta","wrong":"from causalml.meta import SLearner","symbol":"SLearner","correct":"from causalml.inference.meta import SLearner"},{"note":"In v0.14, forest module moved to causalml.inference.forest","wrong":"from causalml.forest import CausalForest","symbol":"CausalForest","correct":"from causalml.inference.forest import CausalForest"},{"note":"Propensity score utilities moved to causalml.propensity in v0.13","wrong":"from causalml.ufb import set_rfub","symbol":"set_rfub","correct":"from causalml.propensity import set_rfub"}],"quickstart":{"code":"import pandas as pd\nimport numpy as np\nfrom causalml.dataset import make_uplift_classification\nfrom causalml.inference.meta import LRSLearner\n\n# Generate synthetic uplift data\nnp.random.seed(42)\ndf, x_names = make_uplift_classification(n_samples=1000, treatment_name=['treatment', 'control'], y_name='y', random_seed=42)\n\n# Train S-learner with logistic regression\nlearner = LRSLearner()\nlearner.fit(df[x_names].values, df['treatment'].values, df['y'].values)\n\n# Predict uplift for each sample\nuplift = learner.predict(df[x_names].values)\nuplift[:5]","lang":"python","description":"Generate synthetic data and train a simple meta-learner to estimate uplift."},"warnings":[{"fix":"Use `from sklearn.linear_model import LogisticRegression; SLearner(learner=LogisticRegression())` instead of `SLearner(learner='lr')`","message":"In v0.14, the causalml.inference.meta module was restructured. BaseLearner subclasses like SLearner, TLearner, XLearner no longer accept string params for model constructors; pass model objects directly.","severity":"breaking","affected_versions":">=0.14"},{"fix":"Use `from causalml.inference.forest import UpliftRandomForestClassifier` instead of any import from `causalml.inference.tree`","message":"The `causalml.inference.tree` module was removed in v0.15. Uplift tree models are now in `causalml.inference.forest` or should be imported from the forest module.","severity":"breaking","affected_versions":">=0.15"},{"fix":"Replace `from causalml.dataset import synthetic_data` with `from causalml.dataset import make_uplift_classification`","message":"The function `causalml.dataset.synthetic_data` is deprecated in favor of `causalml.dataset.make_uplift_classification`.","severity":"deprecated","affected_versions":">=0.13"},{"fix":"Use importance values for ranking features only, not for hypothesis testing.","message":"CausalML's feature importance methods (e.g., `plot_importance()`) may produce different scales than sklearn's built-in importance. Interpretation is relative, not absolute.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `pandas.get_dummies()` or `sklearn.preprocessing.OneHotEncoder` before fitting.","message":"When using S-Learner or T-Learner with categorical features, ensure you one-hot encode them first. The underlying models may not handle cat codes correctly.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace `from causalml.inference.meta import USM` with `from causalml.inference.meta import SClassifier`","message":"The `causalml.inference.meta.USM` (Uplift S-Model) class is deprecated as of v0.16. Use `SClassifier` or `SRegressor` instead.","severity":"deprecated","affected_versions":">=0.16"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `from causalml.inference.meta import SLearner`","cause":"Wrong import path after module restructuring in v0.12.","error":"ImportError: cannot import name 'SLearner' from 'causalml.meta'"},{"fix":"Install with all extras: `pip install causalml[all]`, or ensure `pandas` and `scikit-learn` are present.","cause":"CausalML's dataset module may not be installed if using a slim install (without optional dependencies).","error":"AttributeError: module 'causalml' has no attribute 'dataset'"},{"fix":"Encode treatment as 0 (control) and 1 (treatment). Drop or merge other groups.","cause":"Treatment column passed to a meta-learner contains more than two distinct values (e.g., 0,1,2). Uplift models generally support binary treatment.","error":"ValueError: The 'treatment' column must be binary. Got 3 unique values."},{"fix":"Pass a model instance: e.g., `from sklearn.ensemble import RandomForestClassifier; SLearner(learner=RandomForestClassifier())`","cause":"Using a string for the learner parameter, which was removed in v0.14.","error":"TypeError: __init__() got an unexpected keyword argument 'learner'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}