sf_crime_17.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fpr, tpr, thresholds = roc_curve(y_validation, y_pred) | |
fig = make_subplots( | |
rows=1, cols=2, | |
subplot_titles=( | |
"ROC Curve", | |
"Precision vs Recall Curve" | |
) | |
) | |
# ROC curve | |
# add dotted line to show the performance of randomly guessing (50%) | |
fig.add_trace(go.Scatter( | |
x=[0, 1], | |
y=[0, 1], | |
line=dict( | |
color='royalblue', | |
width=2, | |
dash='dash' | |
) | |
), row=1, col=1) | |
fig.update_layout(showlegend=False) | |
# plot ROC curve, filling the margin above (or below!) the random guess line | |
fig.add_trace(go.Scatter( | |
x=fpr, | |
y=tpr, | |
fill='tonexty', | |
mode='lines', | |
), row=1, col=1) | |
fig['layout']['xaxis']['title'] = dict(text='FPR') | |
fig['layout']['yaxis']['title'] = dict(text='TPR') | |
# precision-recall curve | |
precision, recall, thresholds = precision_recall_curve(y_validation, y_pred) | |
fig_prc = px.area( | |
x=recall, y=precision, | |
title=f'Precision-Recall Curve (AUC={auc(fpr, tpr):.4f})', | |
labels=dict(x='Recall', y='Precision'), | |
width=700, height=500 | |
) | |
fig.add_trace(fig_prc.data[0], row=1, col=2) | |
fig['layout']['xaxis2']['title'] = dict(text='Recall') | |
fig['layout']['yaxis2']['title'] = dict(text='Precision') | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment