Online Causal Machine Learning in Python
Project description
Causal inference for the real world — one observation at a time.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f39004990b78bf732bb3b01144090f4e3e22b2647153b5f4b7328a4afd5004f
|
|
| MD5 |
b3b6144d800dcaa020479fd8f288cc8d
|
|
| BLAKE2b-256 |
b99bc5089b30f62acc6804625fd355ca4a42b94cd07925a49de1b31562848740
|
Provenance
The following attestation bundles were made for onlinecml-1.0.0.tar.gz:
Publisher:
publish.yml on athammad/onlinecml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onlinecml-1.0.0.tar.gz -
Subject digest:
5f39004990b78bf732bb3b01144090f4e3e22b2647153b5f4b7328a4afd5004f - Sigstore transparency entry: 1355793525
- Sigstore integration time:
-
Permalink:
athammad/onlinecml@19cc28168a49bedf52648d00ad1f1e3fedbc4f90 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/athammad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19cc28168a49bedf52648d00ad1f1e3fedbc4f90 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
548424e394e090c4ce954f0981248af5b50e04ecadd063e4f59c3dd7aeb5d20d
|
|
| MD5 |
2b170ee60ef2eb045493f5d469f7a082
|
|
| BLAKE2b-256 |
cc9b7efb118651932796ca8e80fd8397fe89496b9fff9e159302dfc16ccb0a3f
|
Provenance
The following attestation bundles were made for onlinecml-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on athammad/onlinecml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onlinecml-1.0.0-py3-none-any.whl -
Subject digest:
548424e394e090c4ce954f0981248af5b50e04ecadd063e4f59c3dd7aeb5d20d - Sigstore transparency entry: 1355793543
- Sigstore integration time:
-
Permalink:
athammad/onlinecml@19cc28168a49bedf52648d00ad1f1e3fedbc4f90 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/athammad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19cc28168a49bedf52648d00ad1f1e3fedbc4f90 -
Trigger Event:
release
-
Statement type: