Metadata-Version: 2.4
Name: pysurvex
Version: 0.1.0
Summary: Model-agnostic explainability for survival analysis models.
Author: Vatsal Ved
License: MIT License
        
        Copyright (c) 2026 pysurvex contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/vedvatsal3/pysurvex
Project-URL: R survex (reference), https://modeloriented.github.io/survex/
Keywords: survival-analysis,explainability,xai,interpretability
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scikit-survival
Requires-Dist: scikit-learn
Requires-Dist: matplotlib
Requires-Dist: pycox>=0.2.3
Requires-Dist: torch>=2.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: license-file

# pysurvex

**Model-agnostic explainability for survival analysis models in Python.**

`pysurvex` is a Python adaptation of the R package
[`survex`](https://modeloriented.github.io/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:

```bash
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)`:

```python
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

- R package: https://modeloriented.github.io/survex/
- Paper: Spytek et al., *survex: an R package for explaining machine learning
  survival models*, Bioinformatics, 2023.

## License

MIT -- see [LICENSE](LICENSE).
