I am dealing with a classification problem with a dataset containing 60k rows: 69k are negative class, and 1k is positive. I trained my models and I obtained the confusion matrices with a threshold of 0.5 (by default). If I decrease the threshold results improve. I found that the best results are with threshold 0. But what does it mean threshold 0, is it useful? Or is it better also a threshold of 0.01 with slightly worse?
-
1$\begingroup$ A threshold of $0$ means that you call every observation category $1$, so you get the higher accuracy by ignoring what you observe and calling everything $1$ than you do by following your model output. What ROCAUC do you get? $\endgroup$– DaveCommented Jan 15, 2021 at 19:09
-
$\begingroup$ @Dave I edited the post with all the info. So you are suggesting to avoid threshold 0, right? $\endgroup$– CasellaJrCommented Jan 15, 2021 at 19:19
-
1$\begingroup$ What is the metric you are optimizing? What is the purpose of this classifier? How it would be used? How do the predictions translate to solving a business problem? $\endgroup$– TimCommented Oct 12, 2022 at 7:42
3 Answers
You can plot the ROC curve and the point that makes max the TPR and min the FPR. It does not requiere too much code, but I don't know if code is allowed in this channel. Another solution could be to rebalance the target distribution. There are some methods to achieve this. Take a look at SMOTE
Talking about threshold = 0, as Dave and Mark has said, it would mean that your model would classify EVERY observation into one group, totally ignoring the other one. IMO, this would make the model senseless, since you don't need a model to "predict" always the same value, so I would avoid threshold = 0 (or = 1)
-
3$\begingroup$ Our Frank Harrell has some thoughts about SMOTE posted on his Twitter: twitter.com/f2harrell/status/1062424969366462473. $\endgroup$– DaveCommented Jan 15, 2021 at 19:43
-
$\begingroup$ Yeah, I agree with him, is not the best option. I would try to avoid changing the data as much as possible, but some people don't mind doing it. $\endgroup$ Commented Jan 15, 2021 at 19:49
-
1$\begingroup$ Yes, I have already done steps like SMOTE and ROC curve. I just wanted to understand if i could accept a threshold of 0. My dataset also after SMOTE is highly umbalanced and my platform, Microsoft Azure, can not do undersampling. So I will use a threshold of 0.01-0.1. Thank you $\endgroup$ Commented Jan 15, 2021 at 20:46
For a highly unbalanced data set like yours, a model that always predicts 1 (as Dave was discussing) will always have high values for the metrics you're displaying. You need to focus on the negative predictions; if the interface you're using allows the selection of the metric true negative rate (also called specificity or selectivity) use that. If such an option is not available, see if you can switch from identifying 1 as the positive label to identifying 1 as the negative label; I think that would put the focus on the negative labels where it belongs.
-
$\begingroup$ No Microsoft Azure does not have the metrics of specificity and sensitivity. I have not understood the solution that you proposed.. $\endgroup$ Commented Jan 15, 2021 at 20:47
-
$\begingroup$ Your screen shot shows, "Positive label 0 Negative label 1". Does the interface give you the ability to switch that, so it's "Positive label 1 Negative label 0"? $\endgroup$ Commented Jan 15, 2021 at 22:20
-
$\begingroup$ Looking at your positive and negative counts by score bin, it seems your model does a reasonable job of identifying negative cases. What are the values of the metrics if you leave the threshold at the default value of 0.5? $\endgroup$ Commented Jan 15, 2021 at 22:58
-
$\begingroup$ I can do all the analysis again, saying "pos" = 0 and "neg" = 1. But I have not understood what does it change in this way... $\endgroup$ Commented Jan 16, 2021 at 14:25
-
$\begingroup$ Post the results and we can discuss it. $\endgroup$ Commented Jan 19, 2021 at 15:25
I had come cross similar imbalanced data recently and by using F1 score metrics, I picked up 0.09 as best classification threshold. So as other suggests, you should use other metrics (F1 score in scikit) to decide best threshold.
I also observed SMOTE provides reasonable results for imbalanced data.