I've trained a logistic regression model on sklearn and then used it on some sample data which outputted accuracy, sensitivity and specificity values. Is there a way I can use the number of samples tested to estimate some form of confidence intervals for these metrics? i.e. how confident am I that the accuracy is the calculate 87%, and can I calculate a range like 84%-90%? Many thanks
-
$\begingroup$ Accuracy is a proportion, is it not? $\endgroup$– DaveCommented Feb 8, 2022 at 15:55
-
1$\begingroup$ Hint: if your sample data is a random subsample of overall population data, then the success or failure of the model on each event is an independent trial with some unknown probability p -- what distribution describes the random variable of the number of successes? $\endgroup$– jwimberleyCommented Feb 8, 2022 at 15:58
1 Answer
Let me start by saying that accuracy is not an amazing metric. Not only can it be gamed very easily by guessing the most prominent class, but it also is not a proper scoring rule. Meaning that choosing the model with the largest accuracy does not mean choosing the model which best models the data. Additionally, sensitivity/specificity are poor measures of performance when we intend to use the model prospectively since they get the order of conditioning wrong (sens/spec condition on the outcome. We can't condition on the outcome prospectively, that's the whole point of making a model). With that aside, there may be ways to none the less obtain a confidence interval for accuracy.
Accuracy is just a binomial outcome (number correct over number predicted), so you could apply any number of binomial confidence intervals. Ideally, you would use the test set to do this, but there are other ways to doing this which benefit from larger samples.
In particular, you could bootstrap the optimism corrected bootstrap as shown here. That example uses the {rms}
library, but I've created a blog post showing how to do the optimism corrected bootstrap with python and sklearn here.
-
1$\begingroup$ +1, and here is the relevant thread: Why is accuracy not the best measure for assessing classification models? $\endgroup$ Commented Feb 8, 2022 at 15:59