DoubleML

raw JSON →
0.11.2 verified Sat May 09 auth: no python

DoubleML provides an implementation of double/debiased machine learning for causal inference. Current version is 0.11.2, requiring Python >=3.10. Release cadence is irregular, with several minor releases per year.

pip install doubleml
error ImportError: cannot import name 'DoubleMLData' from 'doubleml.data'
cause DoubleMLData was moved to the top-level `doubleml` package in v0.10.0.
fix
Change import to from doubleml import DoubleMLData.
error ImportError: cannot import name 'DoubleMLPLR' from 'doubleml'
cause The class name might be misspelled or older version used a different name (e.g., DoubleMLPLR is correct, but DoubleMLLPLR exists since v0.11.0).
fix
Ensure correct spelling: from doubleml import DoubleMLPLR for partially linear regression model.
error AttributeError: 'DoubleMLPLR' object has no attribute 'rmses'
cause The `rmses` property was renamed to `nuisance_loss` in v0.8.2.
fix
Use model.nuisance_loss instead of model.rmses.
error ValueError: The nuisance model for the treatment 'ml_m' could not be fitted because it is a classifier and the treatment variable has more than two categories.
cause LogisticRegressionCV only works for binary treatment. For multi-category treatment, use a different classifier or treat treatment as continuous.
fix
Ensure treatment variable is binary, or use a multi-class classifier like RandomForestClassifier.
breaking DoubleMLData import path changed in v0.10.0. Previously `from doubleml.data import DoubleMLData`, now `from doubleml import DoubleMLData`. Old code will raise ImportError.
fix Use `from doubleml import DoubleMLData`. For panel data, use `from doubleml import DoubleMLPanelData`.
deprecated The `rmses` property for classifiers is deprecated since v0.8.2. Use `nuisance_loss` instead.
fix Replace `model.rmses` with `model.nuisance_loss`.
gotcha Hyperparameter tuning with Optuna requires the 'optuna' extra. Install with `pip install doubleml[optuna]`.
fix Install the optional dependency: `pip install doubleml[optuna]`.
gotcha DoubleMLData constructor expects numpy arrays or pandas DataFrame/Series. Passing raw lists may cause errors.
fix Convert lists to numpy arrays or pandas objects before passing to DoubleMLData.
pip install doubleml[optuna]

Basic causal effect estimation using DoubleML with Lasso and logistic regression learners.

import doubleml as dml
from sklearn.linear_model import LassoCV, LogisticRegressionCV
import numpy as np

# Generate synthetic data
np.random.seed(42)
n = 500
X = np.random.normal(0, 1, (n, 20))
d = np.random.binomial(1, 1/(1+np.exp(-X[:, 0])), size=n)
y = d * 0.5 + X[:, 0] + np.random.normal(0, 1, n)

# Create DoubleML data object
dml_data = dml.DoubleMLData.from_arrays(
    y=y, d=d, x=X
)

# Initialize model (Partially Linear Regression Model)
model = dml.DoubleMLPLR(
    obj_dml_data=dml_data,
    ml_g=LassoCV(),
    ml_m=LogisticRegressionCV()
)

# Fit and summarize
model.fit()
print(model.summary)