Skip to content

bips-hb/survinng

Repository files navigation

survinng: Gradient-based Explanations for Deep Learning Survival Models

survinng website License: MIT arXiv Website Lifecycle: experimental R-CMD-check

The package survinng provides gradient-based feature attribution methods for deep learning survival models. It implements novel adaptions of model-specific XAI methods for the survival analysis domain, like Grad(t), SG(t), GxI(t), IntGrad(t), and GradSHAP(t). The whole package is designed to be compatible with the survivalmodels package in R, which is an R wrapper for the pycox Python package. However, it can also be used with models from pycox directly and other survival models loaded in torch. Currently, the package supports the models types DeepSurv/CoxPH, DeepHit, and CoxTime.

🚀 Why survinng?

With survinng, you get:

  • Model-specific and time-resolved feature attributions for individuals
  • ⚡️ Fast and scalable explanations using model gradients, especially for SHAP-like explanations
  • 🤝 Compatible with survivalmodels and pycox models
  • 📊 Easy-to-use visualization tools for temporal insights
  • 🔀 Support for multimodal inputs (e.g., tabular + image)

Overall, this package is part of the following ICML'25 paper:

📄 Based on the ICML 2025 paper:
Gradient-based Explanations for Deep Learning Survival Models
Sophie Hanna Langbein, Niklas Koenen, Marvin N. Wright

📦 Installation

To install the latest development version directly from GitHub:

# install.packages("devtools")
devtools::install_github("bips-hb/survinng")

📖 Usage

You have a trained survival neural network model from survivalmodels or pycox and your model input data data. Now you want to interpret individual data points by using the methods from the package survinng, then stick to the following pseudo code:

library(survinng)

# Load a survival model and corresponding data
model <- ... (e.g., from survivalmodels or pycox)
data <- ... (e.g., the test set of the model)

# Create explainer object
explainer <- survinng::explain(model, data)

# Compute feature attributions
idx <- 1 # index of the instance to explain
grad <- surv_grad(explainer, instance = idx) # Grad(t)
sg <- surv_smoothgrad(explainer, instance = idx) # SG(t)
gxi <- surv_grad(explainer, instance = idx, times_input = TRUE) # GxI(t)
ig <- surv_intgrad(explainer, instance = idx) # IntGrad(t)
shap <- surv_gradSHAP(explainer, instance = idx) # GradSHAP(t)

# Plot results
plot(shap)

👉 For full documentation and advanced use cases, visit the 📘 package website.

💻 Quick Example

library(survival)
library(callr)

# Load lung dataset
data(cancer, package="survival")
data <- na.omit(cancer[, c(1, 4, 5, 6, 7, 10, 2, 3)])
train <- data[1:150, ]
test <- data[151:212, ]

# Train a DeepSurv model
ext <- callr::r(function(train) {
  library(survivalmodels)
  library(survival)
  
  # Fit the DeepSurv model
  install_pycox(install_torch = TRUE) # Requires pycox
  fit <- deepsurv(Surv(time, status) ~ ., data = train, epochs = 100,
                  early_stopping = TRUE)

  # Extract the model
  survinng::extract_model(fit)
}, args = list(train = train))


# Create explainer
explainer <- explain(ext, data = test)

# Run GradSHAP(t)
shap <- surv_gradSHAP(explainer)

# Plot results
plot(shap)

🖥 Other Examples and Articles

📚 Citation

If you use this package in your research, please cite it as follows:

@article{langbein2025grad,
  title={Gradient-based Explanations for Deep Learning Survival Models},
  author={Langbein, Sophie Hanna and Koenen, Niklas and Wright, Marvin N.},
  journal={arXiv preprint arXiv:2502.04970},
  year={2025}
}

About

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

Languages