Created
December 24, 2020 02:57
-
-
Save audhiaprilliant/61423842402435bda8dbf2e97460a3ca 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 ROC curve | |
| fpr, tpr, thresholds = roc_curve(y_test, y_pred) | |
| # Plot the ROC curve | |
| df_fpr_tpr = pd.DataFrame({'FPR':fpr, 'TPR':tpr, 'Threshold':thresholds}) | |
| df_fpr_tpr.head() | |
| # Create the data viz | |
| plotnine.options.figure_size = (8, 4.8) | |
| ( | |
| ggplot(data = df_fpr_tpr)+ | |
| geom_point(aes(x = 'FPR', | |
| y = 'TPR'), | |
| size = 0.4)+ | |
| geom_line(aes(x = 'FPR', | |
| y = 'TPR'))+ | |
| labs(title = 'ROC Curve')+ | |
| xlab('False Positive Rate')+ | |
| ylab('True Positive Rate')+ | |
| theme_minimal() | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment