Untitled
import pandas as pd import plotly.graph_objects as go from sklearn.metrics import roc_auc_score, roc_curve # Load CSV files df_model_1 = pd.read_csv('model_1_predictions.csv') df_model_2 = pd.read_csv('model_2_predictions.csv') # Assuming the true labels are in 'True_Label', and predictions/probabilities are in 'Prediction' and 'Probability' y_true = df_model_1['True_Label'] # Assuming both models have the same true labels # Model 1 AUC fpr_1, tpr_1, _ = roc_curve(y_true, df_model_1['Probability']) auc_1 = roc_auc_score(y_true, df_model_1['Probability']) # Model 2 AUC fpr_2, tpr_2, _ = roc_curve(y_true, df_model_2['Probability']) auc_2 = roc_auc_score(y_true, df_model_2['Probability']) # Create plotly figure fig = go.Figure() # Add ROC curve for Model 1 fig.add_trace(go.Scatter(x=fpr_1, y=tpr_1, mode='lines', name=f'Model 1 AUC = {auc_1:.2f}', line=dict(color='blue'))) # Add ROC curve for Model 2 fig.add_trace(go.Scatter(x=fpr_2, y=tpr_2, mode='lines', name=f'Model 2 AUC = {auc_2:.2f}', line=dict(color='red'))) # Add diagonal line for random model fig.add_trace(go.Scatter(x=[0, 1], y=[0, 1], mode='lines', name='Random Model', line=dict(color='gray', dash='dash'))) # Update layout fig.update_layout( title='ROC Curve for Model 1 and Model 2', xaxis_title='False Positive Rate', yaxis_title='True Positive Rate', showlegend=True, template='plotly', xaxis=dict(scaleanchor="y", range=[0, 1]), yaxis=dict(range=[0, 1]), plot_bgcolor='white' ) # Show plot fig.show()
Leave a Comment