survshap
Overview
The survshap package contains an implementation of the SurvSHAP(t) method, the first time-dependent explanation method for interpreting survival black-box models. It is based on SHapley Additive exPlanations (SHAP) but extends it to the time-dependent setting of survival analysis. SurvSHAP(t) is able to detect time-dependent variable effects and its aggregation determines the local variable importance.
Read more about SurvSHAP(t) in our paper.
Installation
You can install the package from PyPI:
pip install survshap
NOTE: SurvSHAP(t) is also implemented in the survex R package, along with many more explanation methods for survival models. survex offers explanations for scikit-survival models loaded into R via the reticulate package.
Citation
If you use this package, please cite our paper:
@article{survshap,
title = {SurvSHAP(t): Time-dependent explanations of machine learning survival models},
journal = {Knowledge-Based Systems},
volume = {262},
pages = {110234},
year = {2023},
issn = {0950-7051}
}
Basic usage
# import packages and load data
from survshap import SurvivalModelExplainer, PredictSurvSHAP, ModelSurvSHAP
from sksurv.ensemble import RandomSurvivalForest # or any other survival model
# X, y - data
# prepare survival model
model = RandomSurvivalForest()
model.fit(X, y)
# create explainer
explainer = SurvivalModelExplainer(model = model, data = X, y = y)
# compute SHAP values for a single instance
observation_A = X.iloc[[0]]
survshap_A = PredictSurvSHAP()
survshap_A.fit(explainer = explainer, new_observation = observation_A)
survshap_A.result
survshap_A.plot()
# compute SHAP values for a group of instances
model_survshap = ModelSurvSHAP(calculation_method="treeshap") # fast implementation for tree-based models
model_survshap.fit(explainer = explainer, new_observations = X)
model_survshap.result
model_survshap.plot_mean_abs_shap_values()
model_survshap.plot_shap_lines_for_all_individuals(variable = "variable1")
extracted_survshap = model_survshap.individual_explanations[0] # PredictSurvSHAP object
Metadata
Release files for survshap 0.4.2
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 |
|---|---|---|---|---|
| survshap-0.4.2.tar.gz | 14.5 kB | Without provenance | Details for survshap-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| survshap-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for survshap-0.4.2-py3-none-any.whl |
Total release size: 34.2 kB
Release files / survshap-0.4.2.tar.gz
| Download URL | survshap-0.4.2.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a863147d33011002b03c3df3279f1656756a6e3761dc4867016b179161df8da4
|
|
BLAKE2b-256 checksum How to use checksums |
058a883ff287621301d415e9ba62303c65179d6090d557d7c288cb70a5e37da1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.5
|
Release files / survshap-0.4.2-py3-none-any.whl
| Download URL | survshap-0.4.2-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83fe0a63dc4bf7bb16d5c92b2ccc5dad92c5e794a8b7eb8a22d27db368c6372c
|
|
BLAKE2b-256 checksum How to use checksums |
0601663ebeb02a3a04f4c81aba9993d6a0d02306361cd91b0c49e565e75fbfa1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.5
|
Security for survshap 0.4.2
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.