Long live democracy!
Earlier in the chapter, we explored and confirmed the data censorship issue for the regime durations dataset. Now, it is time to build your first survival curve for estimating average duration.
Your job is to estimate a survival function and plot a survival curve to show the survival probabilities. To estimate the survival function, you will create an instance of the KaplanMeierFitter
object and fit it to the appropriate data columns. The parameter names have been provided for you as you will learn more about fitting survival functions in later chapters.
The pandas
package is loaded as pd
, the matplotlib.pyplot
module is loaded as plt
, and the KaplanMeierFitter
class is imported from lifelines
. The durations DataFrame is loaded and stored as regime_durations
.
This exercise is part of the course
Survival Analysis in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Instantiate a KaplanMeierFitter object kmf
kmf = ____