pythonsurvival-analysiscox-regressionlifelines

how can i extract baseline hazards from a coxPHFitter function in Lifelines and the coefficients for my variates


Below is the sample code I got from the documentation website. I want to access the baseline hazards and the coefficients of the variates. '''

from lifelines import CoxPHFitter
from lifelines.datasets import load_rossi

rossi_dataset = load_rossi()


#rossi_dataset.head()
cph = CoxPHFitter()
cph.fit(rossi_dataset, duration_col='week', event_col='arrest',)

cph.print_summary()

'''


Solution

  • From the lifelines docs:

    To access the coefficients and the baseline hazard directly, you can use params_ and baseline_hazard_ respectively.

    from lifelines import CoxPHFitter
    from lifelines.datasets import load_rossi
    
    rossi_dataset = load_rossi()
    
    
    #rossi_dataset.head()
    cph = CoxPHFitter()
    cph.fit(rossi_dataset, duration_col='week', event_col='arrest',)
    
    print(cph.params_)
    
    print(cph.baseline_survival_)