Commit f8e93c2e authored by Joaquin Torres's avatar Joaquin Torres

changed colors and removed sd

parent e9fad6bd
...@@ -201,42 +201,43 @@ if __name__ == "__main__": ...@@ -201,42 +201,43 @@ if __name__ == "__main__":
# Generate ROC curves # Generate ROC curves
mean_fpr = np.linspace(0, 1, 100) mean_fpr = np.linspace(0, 1, 100)
tprs, aucs = [], [] tprs, aucs = [], []
cmap = plt.get_cmap('tab10') # Colormap for stronger colors
# Loop through each fold in the cross-validation # Loop through each fold in the cross-validation
for fold_idx, (train, test) in enumerate(cv.split(X_train, y_train)): for fold_idx, (train, test) in enumerate(cv.split(X_train, y_train)):
# Fit the model on the training data # Fit the model on the training data
model.fit(X_train[train], y_train[train]) model.fit(X_train[train], y_train[train])
# Use RocCurveDisplay to generate the ROC curve # Use RocCurveDisplay to generate the ROC curve
roc_display = RocCurveDisplay.from_estimator(model, X_train[test], y_train[test], roc_display = RocCurveDisplay.from_estimator(model, X_train[test], y_train[test],
name=f"ROC fold {fold_idx}", alpha=0.3, lw=1, ax=axes[model_idx]) name=f"ROC fold {fold_idx}", alpha=0.6, lw=2,
ax=axes[model_idx], color=cmap(fold_idx % 10))
# Interpolate the true positive rates to get a smooth curve # Interpolate the true positive rates to get a smooth curve
interp_tpr = np.interp(mean_fpr, roc_display.fpr, roc_display.tpr) interp_tpr = np.interp(mean_fpr, roc_display.fpr, roc_display.tpr)
interp_tpr[0] = 0.0 interp_tpr[0] = 0.0
# Append the interpolated TPR and AUC for this fold # Append the interpolated TPR and AUC for this fold
tprs.append(interp_tpr) tprs.append(interp_tpr)
aucs.append(roc_display.roc_auc) aucs.append(roc_display.roc_auc)
# Compute the mean of the TPRs
mean_tpr = np.mean(tprs, axis=0) # Plot the diagonal line representing random guessing
mean_tpr[-1] = 1.0 axes[model_idx].plot([0, 1], [0, 1], linestyle='--', lw=2, color='r', alpha=.8)
mean_auc = auc(mean_fpr, mean_tpr) # Calculate the mean AUC # Compute the mean of the TPRs
# Plot the mean ROC curve mean_tpr = np.mean(tprs, axis=0)
axes[model_idx].plot(mean_fpr, mean_tpr, color='b', mean_tpr[-1] = 1.0
label=r'Mean ROC (AUC = %0.2f)' % mean_auc, mean_auc = auc(mean_fpr, mean_tpr) # Calculate the mean AUC
lw=2, alpha=.8) # Plot the mean ROC curve with a thicker line and distinct color
# Set plot limits and title axes[model_idx].plot(mean_fpr, mean_tpr, color='b', lw=4,
axes[model_idx].set(xlim=[-0.05, 1.05], ylim=[-0.05, 1.05], label=r'Mean ROC (AUC = %0.2f)' % mean_auc, alpha=.8)
title=f"ROC Curve - {model_name} ({group}-{method_names[j]})") # Set plot limits and title
axes[model_idx].legend(loc="lower right") axes[model_idx].set(xlim=[-0.05, 1.05], ylim=[-0.05, 1.05],
title=f"ROC Curve - {model_name} ({group}-{method_names[j]})")
axes[model_idx].legend(loc="lower right")
# Store the DataFrame in the dictionary with a unique key for each sheet # Store the DataFrame in the dictionary with a unique key for each sheet
sheet_name = f"{group}_{method_names[j]}" sheet_name = f"{group}_{method_names[j]}"
scores_sheets[sheet_name] = scores_df scores_sheets[sheet_name] = scores_df
# Saving curves plots
# Adjust layout and save/show figure # Adjust layout and save/show figure
plt.tight_layout() plt.tight_layout()
plt.savefig(f'./output_cv_metrics/curves/{group}_{method_names[j]}.svg', format='svg', dpi=500) plt.savefig(f'./output_cv_metrics/curves/{group}_{method_names[j]}.svg', format='svg', dpi=500)
plt.close(fig) plt.close(fig)
# Store the DataFrame in the dictionary with a unique key for each sheet
sheet_name = f"{group}_{method_names[j]}"
scores_sheets[sheet_name] = scores_df
# Write results to Excel file # Write results to Excel file
with pd.ExcelWriter('./output_cv_metrics/metrics.xlsx') as writer: with pd.ExcelWriter('./output_cv_metrics/metrics.xlsx') as writer:
for sheet_name, data in scores_sheets.items(): for sheet_name, data in scores_sheets.items():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment