All three of the major Python survival analysis packages—convoys, lifelines, and scikit-survival—show how to plot survival curves with Matplotlib.

How to plot survival curves with Plotly and Altair

submited by
Style Pass
2021-06-29 22:30:05

All three of the major Python survival analysis packages—convoys, lifelines, and scikit-survival—show how to plot survival curves with Matplotlib. In some cases, they bake Matplotlib-based plots directly into trained survival model objects, to enable convenient one-liner plot functions.

The downside of this convenience is that the code is hidden, so it's harder to customize or use a different library. In this article, I'll show how to plot survival curves from scratch with both Altair and Plotly. All of the following code lives in a live, executable Jupyter notebook on Binder and the source file can be found in the Crosstab Kite gists repo.

Survival curves describe the probability that a subject of study will “survive” past a given duration of time. This article assumes you're familiar with the concept; if this is the first you've heard of it, lifelines and scikit-survival both have excellent explanations.

Lifelines introduces survival curve estimation with an example about the tenure of political leaders, using a duration table dataset that's included in the package. Each row represents a head of state; the columns of interest are duration, which is the length of each leader's tenure, and observed, which indicates whether the end of each leader's time in office was observed (it would not be observed if that leader died in office or was still in power when the dataset was collected).

Leave a Comment