capre: Causal Price-Elastic Recourse for Clinical and Tabular Risk Models
capre (Causal Price-Elastic Recourse) generates actionable, budget-feasible counterfactual recourse plans by combining:
- DAG & Partial-Knowledge Tier Gating (
DAGSpec,DAGSpec.from_tiers): Excludes non-ancestor diagnostic proxies (such as 48-hour laboratory draw counts and missingness indicators) without requiring a complete clinical DAG (supporting sink-only exclusions or coarse(baseline, levers, mediators, sinks)tiers), while flaggingconfounded_ancestorssharing unmeasured backdoor paths with the outcome. - Abduct-Act-Predict Propagation & Interventional Causal Shapley (
LinearStructuralModel): Propagates upstream interventions through ridge or cubic-spline structural mediator equations and ranks candidate levers by marginal-residual Interventional Causal Shapley efficiency. - Microeconomic Disutility & Effort-Isometric Surface Warping (
LeverSpec,PriceTable): Models shared domain initiation costs (economies of scope), directional convex marginal effort, Incremental Cost-Effectiveness Ratios (icer), Net Clinical Benefit (net_benefit), and effort-isometric coordinate mapsz = Psi_x(x')(PriceTable.elastic_warp_vector), while selecting diverse candidate bundles across clinical domains and lever sets. SuperLearnerStacking & Model-Dependence Bounds (CapreSuperLearner,MahalanobisOverlapIndex): Pairs cross-validated log-loss ensemble predictions with inter-learner dispersionsigma_MD(x')(supporting conservative gatingp_SL(x') + lambda_MD * sigma_MD(x') <= tau*) and Kish Effective Sample Size (overlap_ess) counterfactual support diagnostics.
Installation
pip install capre
Quick Example
from capre import CapreExplainer, CapreSuperLearner, make_icu_hapri_demo
demo = make_icu_hapri_demo(n=1000, seed=42)
sl_anc = CapreSuperLearner(feature_columns=demo.ancestor_columns, seed=42).fit(
demo.df, demo.df[demo.outcome]
)
tau = sl_anc.oof_youden_threshold()
explainer = CapreExplainer.from_superlearner(
causal_superlearner=sl_anc,
train_df=demo.df,
feature_columns=demo.feature_columns,
outcome=demo.outcome,
price_table=demo.price_table,
dag=demo.dag,
)
high_risk_row = demo.df.loc[sl_anc.predict_risk(demo.df) > tau + 0.15].iloc[0]
result = explainer.explain(high_risk_row, threshold=tau, budget=5.0, lambda_md=0.5)
print(result.to_json())
Vignettes and Interactive Companion
- Python PDF Vignette (LaTeX Mini-Manuscript): https://andystats.github.io/capre/vignettes/capre-python-guide.pdf
- Interactive Visual Primer: https://andystats.github.io/capre/
- CAPRE for the Classroom (R & Python Workshops): https://andystats.github.io/capre/classroom/
Metadata
Release files for capre 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| capre-0.3.0.tar.gz | 46.4 kB | Without provenance | Details for capre-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| capre-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for capre-0.3.0-py3-none-any.whl |
Total release size: 86.7 kB
Release files / capre-0.3.0.tar.gz
| Download URL | capre-0.3.0.tar.gz |
|---|---|
| Size | 46.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
217e22b569259f806bfab8bb6977d6e5598d1bafcb190ce2b69397de59cee40e
|
|
BLAKE2b-256 checksum How to use checksums |
02b3bb6cdb8e097b4a1722f42e3931e3d55cb2d5b9a45f2b2faa34b97d969652
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / capre-0.3.0-py3-none-any.whl
| Download URL | capre-0.3.0-py3-none-any.whl |
|---|---|
| Size | 40.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2fdfba800713236294a41ed8b48ef043c57ac34bf89a6e93dab8742953e28c2
|
|
BLAKE2b-256 checksum How to use checksums |
118c803b0795bff721e89d095789e8f1762c73462a4c7bcac253cc6c0c36b716
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for capre 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.