0

I am learning survival analysis using the lifelines library. I am using the leukemia dataset. I was trying to plot the lifetimes plot. However, I am getting a plot which is upside down (i.e., flipped vertically).

I am using this notebook as a reference. This is my code:

import lifelines
import matplotlib.pyplot as plt
from lifelines.datasets import load_leukemia
leukemia = load_leukemia()
durations = leukemia.t.values
events = leukemia.status.values
ax = lifelines.plotting.plot_lifetimes(durations=durations, event_observed=events)
ax.set_xlim(0, 40)
ax.set_xlabel("Time in Months")
plt.plot()

This is the plot that I am getting

This is the plot that I want to generate:

Arturo Moncada-Torres
  • 1,236
  • 14
  • 23
A Q
  • 166
  • 2
  • 13

1 Answers1

0

Although I am not sure which one of the plots is correct, but the lifelines API was updated on 21 Mar 2019 (v. 0.20.2). As per the changelog:

plot_lifetimes no longer reverses the order when plotting.

The github notebook is dated 11 Mar 2019, so I assume it was using the old API that would have resulted in the plot as depicted therein. However, all future versions of lifelines would result in the plot that you are getting.

So basically if you uninstall your current lifelines package and pip install lifelines==0.24.13 (v. 0.24.13 is the latest lifelines version) you will get the plot that you are getting.

Cameron Davidson (lifelines author) might be able to shed some more light on it - may be the Leukemia dataset needs to be updated following the API change!

finlytics-hub
  • 164
  • 1
  • 9