Time-to-event prediction with PyTorch
Get Started • Methods • Evaluation Criteria • Datasets • Installation • References
pycox is a Python package for survival analysis and time-to-event prediction with PyTorch, built on the torchtuples package for training PyTorch models. An R version of this package is available at survivalmodels.
The package contains implementations of various survival models, some useful evaluation metrics, and a collection of event-time datasets. Additionally, some useful preprocessing tools are available in the pycox.preprocessing module.
Get Started
To get started, you first need to install PyTorch.
After that, you can install pycox via pip:
pip install pycox
OR, via conda:
conda install -c conda-forge pycox
We recommend starting with 01_introduction.ipynb, which explains the general usage of the package in terms of preprocessing, creation of neural networks, model training, and evaluation procedure.
Methods
The following methods are available in the pycox.methods module.
Continuous-Time Models:
Method | Description | Example |
---|---|---|
CoxTime | Cox-Time is a relative risk model that extends Cox regression beyond the proportional hazards. | Notebook |
CoxCC | Cox-CC is a proportional version of the Cox-Time model. | Notebook |
CoxPH (DeepSurv) | CoxPH is a Cox proportional hazards model also referred to as DeepSurv. | Notebook |
PCHazard | The Piecewise Constant Hazard (PC-Hazard) model assumes that the continuous-time hazard function is constant in predefined intervals. | Notebook |
Discrete-Time Models:
Method | Description | Example |
---|---|---|
LogisticHazard (Nnet-survival) | The Logistic-Hazard method parameterizes the discrete hazards and optimizes the survival likelihood. | Notebook |
PMF | The PMF method parameterizes the probability mass function (PMF) and optimizes the survival likelihood. | Notebook |
Evaluation Criteria
The following evaluation metrics are available with pycox.evaluation.EvalSurv.
Metric | Description |
---|---|
concordance_td | The time-dependent concordance index evaluated at the event times. |
brier_score | The IPCW Brier score (inverse probability of censoring weighted Brier score). |
Datasets
A collection of datasets are available through the pycox.datasets module.
For example, the following code will download the metabric dataset and load it in the form of a pandas dataframe:
from pycox import datasets
df = datasets.metabric.read_df()
Installation
**Note:** This package is still in its early stages of development, so please report any problems you may experience. The package only works for Python 3.6+.
Before installing pycox, please install PyTorch (version = 1.1). You can then install the package with:
pip install pycox
For the bleeding-edge version, you can install directly from GitHub:
pip install git+git://github.com/havakv/pycox.git
Troubleshooting
Always ensure that your Python version is compatible (3.6+) and that you have the right version of PyTorch installed, as conflicts can often arise from version mismatches. If you face any issues, it’s a good idea to check the common pitfalls in Python package installations. Sometimes, re-installing the packages resolves hidden conflicts.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.