Skip to content

Instantly share code, notes, and snippets.

@audhiaprilliant
Created December 24, 2020 03:02
Show Gist options
  • Select an option

  • Save audhiaprilliant/2b6e582a2a8deb7085c5d41b27cbee02 to your computer and use it in GitHub Desktop.

Select an option

Save audhiaprilliant/2b6e582a2a8deb7085c5d41b27cbee02 to your computer and use it in GitHub Desktop.
How to choose the optimal threshold for imbalanced classification
# Create the Precision-Recall curve
precision, recall, thresholds = precision_recall_curve(y_test, y_pred)
# Plot the ROC curve
df_recall_precision = pd.DataFrame({'Precision':precision[:-1],
'Recall':recall[:-1],
'Threshold':thresholds})
df_recall_precision.head()
# Creat a data viz
plotnine.options.figure_size = (8, 4.8)
(
ggplot(data = df_recall_precision)+
geom_point(aes(x = 'Recall',
y = 'Precision'),
size = 0.4)+
geom_line(aes(x = 'Recall',
y = 'Precision'))+
labs(title = 'Recall Precision Curve')+
xlab('Recall')+
ylab('Precision')+
theme_minimal()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment