Survival Analysis: Censored Data and Hazards
Module: Machine Learning | Difficulty: Advanced
Survival Function
Hazard Function
Cox Proportional Hazards
Kaplan-Meier Estimator
where = deaths at time , = at risk.
Censored Data
import numpy as np
from lifelines import CoxPHFitter
class CoxModel:
def __init__(self):
self.cph = CoxPHFitter()
def fit(self, df, duration_col, event_col):
self.cph.fit(df, duration_col=duration_col, event_col=event_col)
def predict_survival(self, X):
return self.cph.predict_survival_function(X)
def predict_partial_hazard(self, X):
return self.cph.predict_partial_hazard(X)
Research Insight: Random survival forests outperform Cox regression when the proportional hazards assumption is violated. The key advantage is that they can capture non-linear effects and interactions automatically.