Skip to content

Instantly share code, notes, and snippets.

@aagnone3
Created October 30, 2020 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aagnone3/f249a78db38d79e0d4cede0e434b1666 to your computer and use it in GitHub Desktop.
Save aagnone3/f249a78db38d79e0d4cede0e434b1666 to your computer and use it in GitHub Desktop.
sf_crime_17.py
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