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.1.0.tar.gz (53.0 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.1.0-py3-none-any.whl (77.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for onlinecml-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e9cf226943de6c78c3a95e6df654f8d7e001ee8a12b01295c608c46852e4f1cb
MD5 693c099bc74ddaf68dce5f9056804ff4
BLAKE2b-256 81773b05b85f5b03a8233227b526af1e0e3167cb7dbac0ddeba65b9b645c827e

See more details on using hashes here.

Provenance

The following attestation bundles were made for onlinecml-1.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: onlinecml-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 77.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63de96206fc3f7fd5864d35bd960f07d8c7c0d2c39bb1d0f1f55d28707f4cd19
MD5 772e5e8719d55bbd9dfc0463d9b54d3f
BLAKE2b-256 d2b90cf2fdeef9a5bbf5783860657c361984094ebce2f868163819d968b0b437

See more details on using hashes here.

Provenance

The following attestation bundles were made for onlinecml-1.1.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