# Calculate confidence score of a neural network prediction

I am using a deep neural network model to make predictions. My problem is a classification(binary) problem. I wish to calculate the confidence score of each prediction. As of now, I use predict_proba of sklearn to get probability of a class and consider it as the model confidence for that prediction. Is it the right approach? What could be a better way to calculate the confidence score? Kindly add relevant literature to support your approach.

• You mean something like NGboost but for NN? stanfordmlgroup.github.io/projects/ngboost Jan 21 '20 at 10:49
• Ya something like this @CarlosMougan Jan 21 '20 at 10:58
• Just to be clear: if indeed these probabilities are well-calibrated, using them directly is the right approach in order to capture model confidence for that prediction. Jun 3 at 2:20

One way to estimate the level of confidence we have about an ANN prediction is to use dropout perturbations. The idea was proposed in this paper: Dropout as a Bayesian Approximation. Representing Model Uncertainty in Deep Learning. The core idea is to use dropout as a perturbation method, and check how predictions change with varying levels of dropout. Once you sampled a sufficient number of "distorted predictions", you can estimate something analogous to a confidence interval around the initial model prediction. This technique works either for classifiers and regressors.

You can read an explanation of this approach here.

EDIT:

To be more precise:

In order to implement this technique, use Dropout() layers, they can be used in prediction phase too (not just during training). You can train your Neural Network, then transfer its weights into another ANN with the same architecture + dropout layers. Something like:

new_model.set_weights(original_model.get_weights())

Once the new ANN with Dropout() has its weights, run it and vary its dropout hyperparams, get the predictions and calculate the CIs. I know it's time consuming so do it only if you think it's really worth it. Another possible way to implement can be done with custom layers like:

model.add(Lambda(lambda x: K.dropout(x, level=0.5)))

• this seems interesting... Btw what do you think about using probabilities as confidence score for each prediction? Jan 21 '20 at 11:39
• According to this technique, you would generate many predictions using varying level of dropout (as many as possible). Then you look at the distribution of these predictions (for each dropout level) and you build a confidence interval around them. Of course this is very time consuming Jan 21 '20 at 14:26
• the sole reason I am not working on this technique is the enormous time consumption. Also, by confidence I understand probability that the class assigns to object x by the classifier. So I am pretty much confused that why can't I simply use the values from predict_proba as confidence in prediction. Kindly help me here. Jan 21 '20 at 14:55
• yeah, computation is the problem. The reason is that predict_proba makes sense only if a model allows you to calculate confidence intervals around its predictions. ANNs don't allow that, that's why tricks (such as the dropout perturbation) have been invented. With classifiers, when you softmax the output you can interpret values as the probability of belonging to each specific class. You can use their distribution as a rough measure of how confident you are that an observation belongs to that class. It's simplistic but it can work, and it comes with no additional computational costs. Jan 21 '20 at 15:50
• Could you share a demo version of the distribution approach you suggested? Jan 21 '20 at 15:55