Python में Survival Analysis
Shae Wang
Senior Data Scientist
Hazard फंक्शन $h(t)$: किसी समय तक जीवित रहने पर, उस समय पर घटना होने की प्रायिकता बताता है.
Hazard rate: घटना होने की तत्क्षण दर.
$$h(t)=-\frac{d}{dt}logS(t)$$
Hazard फंक्शन $h(t)$ और survival फंक्शन $S(t)$ एक-दूसरे से निकाले जा सकते हैं.
Proportional hazards मान्यता: सभी व्यक्तियों के hazards एक-दूसरे के समानुपाती होते हैं.
व्यक्ति $A$ और $B$ के लिए: $$h_A(t)=ch_B(t)$$

Proportional hazards मान्यता के आधार पर: $$h(t|x)=b_0(t)exp\bigg(\sum^{n}_{i=1}b_i(x_i-\overline{x_i}\bigg)$$
$b_0(t)$: जन-स्तरीय baseline hazard फंक्शन, जो समय के साथ बदलता है.
$exp\bigg(\sum^{n}_{i=1}b_i(x_i-\overline{x_i}\bigg)$: covariates और log hazard के बीच रैखिक संबंध, जो समय के साथ नहीं बदलता.
CoxPHFitter क्लास import करें और instantiate करेंfrom lifelines import CoxPHFitter
coxph = CoxPHFitter()
.fit() कॉल कर estimator को डेटा पर फिट करेंcoxph.fit(df, duration_col, event_col)
coxph.summary()
coxph.predict()
mortgage_dfhouseprincipal interest property_taxcredit_scoreduration, paid_offfrom lifelines import CoxPHFittercoxph = CoxPHFitter() coxph.fit(df=mortgage_df, duration_col="duration", event_col="paid_off")
DataFrame फ़िल्टर करें:
new_df = mortgage_df.loc[:,
mortgage_df.columns!="house"]
coxph.fit(df=new_df,
duration_col="duration",
event_col="paid_off")
formula पैरामीटर उपयोग करें:
coxph.fit(df=mortgage_df,
duration_col="duration",
event_col="paid_off",
formula="principal + interest
+ property_tax + credit_score")
print(coxph.summary)
<lifelines.CoxPHFitter: fitted with 1808 observations, 340 censored>
coef exp(coef) se(coef) z p
covariate house -0.38 0.68 0.19. -1.98 0.05
principal -0.06 0.94 0.02 -2.61 0.01
interest 0.31 1.37 0.31 1.02 0.31
property_tax -0.15 0.86 0.21 -0.71 0.48
credit_score -0.43 0.65 0.38 -1.14. 0.26
interest के median से एक unit बढ़ने पर -> hazards $e^{0.31}=1.37$ गुना बदलते हैं, यानी baseline hazards की तुलना में 37% वृद्धि.Python में Survival Analysis