Skip to main content

Model-agnostic explainability for survival analysis models.

Project description

pysurvex

Model-agnostic explainability for survival analysis models in Python.

pysurvex is a Python adaptation of the R package survex. Its goal is to provide a unified, model-agnostic interface for explaining the predictions of survival analysis models (Cox PH, Random Survival Forests, DeepSurv, etc.) using time-dependent variants of popular interpretability methods.

Supported models

Auto-detected (no configuration needed):

  • scikit-survival CoxPHSurvivalAnalysis
  • scikit-survival RandomSurvivalForest
  • pycox DeepSurv (pycox.models.CoxPH)

Any other survival model is supported by supplying a manual predict_survival_function override (see below).

Roadmap

Currently implemented xAI methods:

  • Partial Dependence Profiles (PDP) — via model_profile(..., method="pdp")
  • Accumulated Local Effects (ALE) — via model_profile(..., method="ale")
  • Individual Conditional Expectation (ICE) — via predict_profile(...)

Methods to be implemented

  • SurvLIME
  • SurvSHAP

Installation

For local development:

git clone https://github.com/vedvatsal3/pysurvex.git
cd pysurvex
pip install -e ".[dev]"

Runtime dependencies: numpy, pandas, scikit-survival, scikit-learn. matplotlib is additionally required only when you call a result object's .plot() method — the numeric layer (computing PDP / ICE / ALE matrices) needs only numpy, pandas, and scikit-survival.

Supplying a custom prediction interface

For models that are not auto-detected, pass a predict_survival_function with the signature (model, X, times) -> np.ndarray of shape (n_obs, n_times):

def my_predict(model, X, times):
    # e.g. wrap pycox, lifelines, torchsurv, ...
    return model.survival_matrix(X, times)

explainer = SurvivalExplainer(
    model=my_model,
    data=X,
    y=y,
    predict_survival_function=my_predict,
)

References

License

MIT -- see LICENSE.

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

pysurvex-0.1.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

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

pysurvex-0.1.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file pysurvex-0.1.0.tar.gz.

File metadata

  • Download URL: pysurvex-0.1.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pysurvex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e194a6df1a509a1467a5380582dc131278f285aa1f2e3e1874711202e471b4e2
MD5 86de5561962db9105be98476debfe717
BLAKE2b-256 18559cb5afa2ddc86dd725030b4d0d700283568d9ef68ac5d4c5801ecd554a48

See more details on using hashes here.

File details

Details for the file pysurvex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pysurvex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pysurvex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad56f90e701025b6ab54a7fe94e9bf5833d5f0224c8ddc8effd90d633517d2d4
MD5 3280c8d23f135eca22a34dd8445bb5c1
BLAKE2b-256 73cc1c13841f5dfc6b1c3e745e360f70479b45fefe94007e53f28635e0888b32

See more details on using hashes here.

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