Skip to main content

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:

  1. 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 flagging confounded_ancestors sharing unmeasured backdoor paths with the outcome.
  2. 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.
  3. 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 maps z = Psi_x(x') (PriceTable.elastic_warp_vector), while selecting diverse candidate bundles across clinical domains and lever sets.
  4. SuperLearner Stacking & Model-Dependence Bounds (CapreSuperLearner, MahalanobisOverlapIndex): Pairs cross-validated log-loss ensemble predictions with inter-learner dispersion sigma_MD(x') (supporting conservative gating p_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

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)

Source distribution for capre 0.3.0
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)

Table of built distributions (wheels) for capre 0.3.0
File Interpreter ABI Platform Actions
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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page