Created
December 24, 2020 03:02
-
-
Save audhiaprilliant/2b6e582a2a8deb7085c5d41b27cbee02 to your computer and use it in GitHub Desktop.
How to choose the optimal threshold for imbalanced classification
This file contains hidden or 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
| # 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