# Create a Kaplan-Meier object
kaplanmeierfitter =KaplanMeierFitter()# Create a larger figure to avoid overlap
plt.figure(figsize=(12,8))# Iterate through each unique combination of 'cyto_score', 'tbi_status', 'graft_type', and 'vent_hist'for(cyto_score, tbi_status, graft_type, vent_hist)in data_train.groupby(['cyto_score','tbi_status','graft_type','vent_hist']).groups:# Filter the data based on the current group
group_data = data_train[(data_train['cyto_score']== cyto_score)&(data_train['tbi_status']== tbi_status)&(data_train['graft_type']== graft_type)&(data_train['vent_hist']== vent_hist)]# Fit the Kaplan-Meier model
kaplanmeierfitter.fit(group_data['efs_time'], event_observed=group_data['efs'],
label=f'cyto_score {cyto_score}, tbi_status {tbi_status}, graft_type {graft_type}, vent_hist {vent_hist}')# Plot the survival function with a unique color for each group
kaplanmeierfitter.plot_survival_function(color=plt.cm.tab10(group_data['cyto_score']%10))# Using colormap for variety# Customize the plot
plt.title('Kaplan-Meier Survival Curve')
plt.xlabel('Time (months)')
plt.ylabel('Survival Probability')
plt.legend()
plt.show()
السؤال
Ali Ahmed55
السلام عليكم
ده الكود
4 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.