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.1.tar.gz (25.5 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.1-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysurvex-0.1.1.tar.gz
  • Upload date:
  • Size: 25.5 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.1.tar.gz
Algorithm Hash digest
SHA256 77ae90d9d0dc5d636a6afa25372c9ef31191275971bc8e5c9f750fae72f9122f
MD5 dbb6ec7adb6319896a1729081b9edf1c
BLAKE2b-256 dc03810ecc4134adb1801e792b5c8c57c9dd2b38124fd403489a02cca3738d66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pysurvex-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b93f78c9fc6a5ddfa0e2ac9822253052bd28f224033bc50f7fa3fc9c90e486de
MD5 08819c7447f989fa20e4f471675f53da
BLAKE2b-256 65cf2832f1f61fc7ea3308b7a267fdf25dfee8c5160f2f2de60d9be418cc9a62

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