5

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.

yamini goel
  • 711
  • 3
  • 7
  • 14

1 Answers1

7

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)))

Opsse
  • 103
  • 3
Leevo
  • 6,005
  • 3
  • 14
  • 51
  • this seems interesting... Btw what do you think about using probabilities as confidence score for each prediction? – yamini goel Jan 21 '20 at 11:39
  • 1
    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 – Leevo Jan 21 '20 at 14:26
  • 1
    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. – yamini goel Jan 21 '20 at 14:55
  • 1
    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. – Leevo Jan 21 '20 at 15:50
  • Could you share a demo version of the distribution approach you suggested? – yamini goel Jan 21 '20 at 15:55
  • Unfortunately I don't have an implementation at the moment – Leevo Jan 21 '20 at 16:32
  • that's fine. Do you have some link to explain your approach in a better way? – yamini goel Jan 22 '20 at 09:39
  • I have found [this](https://towardsdatascience.com/uncertainty-estimation-for-neural-network-dropout-as-bayesian-approximation-7d30fc7bc1f2) and [this](https://medium.com/hal24k-techblog/how-to-generate-neural-network-confidence-intervals-with-keras-e4c0b78ebbdf). To implement use `Dropout()` layers, that can be used in prediction phase too (not just training). You can train your ANN, then transfer its weights into another ANN with the same architecture + dropout layers. Vary dropout hyperparams, get the predictions and calculate CIs. I know it's time consuming so do it only if it's worth it. – Leevo Jan 22 '20 at 09:46