الف شكراااا جدا جدا لحضرتك
بس انا عملت داله ودي الكود
# Function to plot Kaplan-Meier survival curve for any categorical group
def plot_kaplan_meier(group_column , plot_title):
kaplanmeierfitter = KaplanMeierFitter()
# Loop through each unique value of the group column
for group in data_train[group_column].unique():
# Filter the data for the current group
group_data = data_train[data_train[group_column] == group]
# Fit the Kaplan-Meier estimator
kaplanmeierfitter.fit(group_data['efs_time'], event_observed=group_data['efs'], label=f"{group_column} {group}")
# Plot the survival function
kaplanmeierfitter.plot_survival_function(ci_show=False)
# Set the title and labels for the plot
plt.title(plot_title)
plt.xlabel("Time(months)") # Label for the x-axis
plt.ylabel("Survival Probability") # Label for the y-axis
# Adjust the layout to avoid clipping
plt.tight_layout()
#plt.savefig("Distribution-of-Survival-Analysis-Prod_Type.png" , bbox_inches='tight')
# Save or show the plot
plt.show()