Skip to main content

Online Causal Machine Learning in Python

Project description

OnlineCML

Causal inference for the real world — one observation at a time.

CI
Coverage Docs

Why OnlineCML?

Every major causal inference library (EconML, CausalML, DoWhy) requires a complete dataset before you begin. But many real-world applications don't have that luxury:

  • A/B tests where you want decisions now, not after 30 days
  • Clinical trials where treatment effects must be monitored continuously
  • Marketing systems where customer data arrives as a stream
  • Any setting where the treatment effect might shift over time

OnlineCML processes one observation at a time. No batches. No waiting.

Installation

pip install onlinecml

Quickstart

from onlinecml.datasets import LinearCausalStream
from onlinecml.reweighting import OnlineIPW

estimator = OnlineIPW()
for x, treatment, outcome, _ in LinearCausalStream(n=1000, true_ate=2.0, seed=42):
    estimator.learn_one(x, treatment, outcome)

print(f"ATE:   {estimator.predict_ate():.3f}")  # → ~2.0
print(f"95%CI: {estimator.predict_ci()}")

Methods

Method Class ATE Individual CATE Doubly Robust
Inverse Probability Weighting OnlineIPW
Augmented IPW OnlineAIPW
Overlap Weights OnlineOverlapWeights
S-Learner OnlineSLearner
T-Learner OnlineTLearner
X-Learner OnlineXLearner
R-Learner OnlineRLearner
Online Matching OnlineMatching
Caliper Matching OnlineCaliperMatching
Causal Hoeffding Tree CausalHoeffdingTree
Online Causal Forest OnlineCausalForest

Novel contributions: CausalHoeffdingTree and OnlineCausalForest implement a custom causal split criterion that maximises between-child CATE variance rather than outcome MSE, with linear leaf models, doubly robust correction, multi-threshold split search, and per-tree ADWIN drift detection.

Policies: EpsilonGreedy, ThompsonSampling, UCB

Diagnostics: OnlineSMD, ATETracker (with convergence plot and forgetting factor), OverlapChecker, ConceptDriftMonitor

Datasets: LinearCausalStream, HeterogeneousCausalStream, DriftingCausalStream, UnbalancedCausalStream, ContinuousTreatmentStream

Evaluation: progressive_causal_score, PEHE, ATEError, UpliftAUC, QiniCoefficient

How it differs from batch libraries

DoWhy EconML CausalML OnlineCML
Online / streaming
One-obs-at-a-time
Concept drift
Exploration policy
River compatible
Online causal forest
IPW / DR / Overlap
Meta-learners
CATE estimation

Documentation

Full documentation and example notebooks at athammad.github.io/onlinecml.

Contributing

See CONTRIBUTING.md. All PRs require unit tests and must maintain >90% coverage.

Citation

@software{onlinecml2025,
  title  = {OnlineCML: Online Causal Machine Learning in Python},
  author = {Hammad, Ahmed},
  year   = {2025},
  url    = {https://github.com/athammad/onlinecml}
}

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onlinecml-1.0.0.tar.gz (52.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onlinecml-1.0.0-py3-none-any.whl (77.4 kB view details)

Uploaded Python 3

File details

Details for the file onlinecml-1.0.0.tar.gz.

File metadata

  • Download URL: onlinecml-1.0.0.tar.gz
  • Upload date:
  • Size: 52.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onlinecml-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5f39004990b78bf732bb3b01144090f4e3e22b2647153b5f4b7328a4afd5004f
MD5 b3b6144d800dcaa020479fd8f288cc8d
BLAKE2b-256 b99bc5089b30f62acc6804625fd355ca4a42b94cd07925a49de1b31562848740

See more details on using hashes here.

Provenance

The following attestation bundles were made for onlinecml-1.0.0.tar.gz:

Publisher: publish.yml on athammad/onlinecml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onlinecml-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: onlinecml-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 77.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onlinecml-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 548424e394e090c4ce954f0981248af5b50e04ecadd063e4f59c3dd7aeb5d20d
MD5 2b170ee60ef2eb045493f5d469f7a082
BLAKE2b-256 cc9b7efb118651932796ca8e80fd8397fe89496b9fff9e159302dfc16ccb0a3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for onlinecml-1.0.0-py3-none-any.whl:

Publisher: publish.yml on athammad/onlinecml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page