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.

ai-mldata
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

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 footguns
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.
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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources