Registry / ai-ml / causalmodels

causalmodels

JSON →
library0.4.0pypypiunverified

Causalmodels is a Python library for defining, analyzing, and inferring causal relationships from data, drawing inspiration from Judea Pearl's do-calculus. It provides tools for building Bayesian causal models, performing matching, and conducting regression-based causal inference. The current version is 0.4.0, with an irregular release cadence.

pip install causalmodels
INSTALL
IMPORT
SIG · CAUSALMODELS
C
causalmodels
ai-mlpythonv0.4.0
Install
9.8s avg
Import
—
Disk
281MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
build_error
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 9.8s · import 0.000s · 271MB
281MB installed
● package 281MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BayesianModel
✓ from causalmodels import BayesianModel
✗ from causalmodels import BayesianModel

This quickstart demonstrates how to use the `Regression` module to estimate the Average Treatment Effect (ATE) of a treatment variable 'X' on an outcome 'Y', while controlling for a confounder 'Z'. It simulates data reflecting a causal relationship and then applies the regression model.

import pandas as pd import numpy as np from causalmodels.regression import Regression # Simulate some data with a known causal effect np.random.seed(42) n_samples = 1000 # Confounder Z affects both Treatment X and Outcome Y Z = np.random.normal(0, 1, n_samples) # Treatment X is affected by Z X = 0.5 * Z + np.random.normal(0, 1, n_samples) # Outcome Y is affected by X and Z Y = 2.0 * X + 1.0 * Z + np.random.normal(0, 1, n_samples) data = pd.DataFrame({'Z': Z, 'X': X, 'Y': Y}) # Initialize the Regression model # X: treatment variable, Y: outcome variable, control_variables: confounders model = Regression(data, treatment='X', outcome='Y', control_variables=['Z']) # Estimate the Average Treatment Effect (ATE) ate_estimate = model.estimate_ate() print(f"Observed data with N={n_samples} samples.") print(f"Estimated Average Treatment Effect (ATE) of X on Y, controlling for Z: {ate_estimate:.4f}")
Debug
Known issues
gotchaCausal inference methods in `causalmodels` (and generally) rely on strong assumptions (e.g., no unmeasured confounders, correct specification of the causal graph). Failing to meet these assumptions can lead to biased estimates.
fix
Carefully define your causal graph, identify all potential confounders, and consider domain knowledge before applying methods. Validate assumptions where possible through sensitivity analysis or alternative approaches.
affects: All
gotchaInput data to `causalmodels` methods must be clean and appropriately preprocessed. Missing values, incorrect data types, or inconsistent column names can lead to errors or silently biased results during estimation.
fix
Ensure your DataFrame is clean, handles missing values (e.g., imputation or removal) appropriately, and all columns used in causal models are of the expected numerical type before passing the data.
affects: All
Upgrade
Version history
0.4.0latest on PyPI · released Jul 20, 2016
Audit
Dependencies
numpyrequiredNumerical operations
scipyrequiredScientific computing
pandasrequiredData manipulation
statsmodelsrequiredStatistical modeling and estimation
scikit-learnrequiredMachine learning utilities and models
Agent activity
24 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
causalmodels — pip install causalmodels · libregistry