5

Conformal Prediction for a Neural Regression Model

 2 years ago
source link: https://pkghosh.wordpress.com/2021/12/30/conformal-prediction-for-a-neural-regression-model/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conformal Prediction for a Neural Regression Model

When a deployed machine learning model makes a prediction, should we accept the prediction on its face value or question the reliability of the prediction. For certain critical applications like medical and aviation, where some decision making is involved post prediction unless there is high confidence associated with the prediction it may be too risky to accept it.

How do you associate a confidence value with the model prediction.It’s tempting to use the probability prediction for a classification as a measure confidence. However the predicted class probability has nothing to do with confidence. This is where conformal prediction enters into the picture. It enables us to associate a confidence level with the model prediction. For decision making system e.g deciding whether to treat patient based on the model prediction of chest X-ray, it’s critical to have a level of confidencve with the model prediction.

In this post we perform conformal prediction for a loan application problem. The regression model predicts the loan amount that can be approved with minimum risk. This is a decision making system that involves financial risk where the confidence level with the prediction should be available. The implementation is available in my OSS Github rep avenir

Conformal Prediction

Machine Learning models make point prediction i.e class label for classification and a numeric value for regression. Conformal prediction converts the point prediction to set based or numerical interval based prediction for classification and regression problems respectively. The set or the interval is also associated with a confidence level.

With conformal prediction for a regression problem you could make statements like “for some input x the range of prediction is between y1 and y2 with a probability of p or higher.” So if the actual prediction from the model is within the prediction range you could accept the prediction with certain level of confidence.

Conformal prediction requires a non conformity score. Non conformity score reflects how different an input is compared to the training data set. For classification it could be (1 – predicted probability) and for regression it could be absolute difference between actual and predicted value.

The steps for the conformal prediction algorithm are are as follows for regression. For classification it’s similar except for few differences

  • For set aside calibration data set, calculate non conformity scores
  • From the distribution of the conformity scores get value corresponding to some upper confidence bound e.g. 0.9 i.e tolerance α of 0.1
  • For any new input x for which the model has predicted yp, for all possible actual y calculate the non conformity scores
  • Save the y values corresponding all cases where the non conformity score is less the non conformity score upper bound from step 2. These y values define the prediction range for the the particular input x. The predictions within this range have a probability of (1 – α) or more of being true
  • If the actual prediction from the model is within the prediction range, then the model prediction is acceptable and is correct with a probability of (1 – α) or more

For classification problems, in step 3 all possible class labels should be considered and non conformity score be computed. In step 4 we will get a prediction set of class labels.

Essentially, what we are doing is to take some candidate actual target values and choosing among them those for which the non conformity score is within the upper confidence bound. If the actual prediction is within the range or set, then the prediction is correct with the same confidence bound.

Loan Amount Regression Model Conformal Prediction

This is a regression model that predicts the loan amount that can be approved given the applicant details as input. Details of the data can be found in an earlier post. The neural network model has the following charactersistics

  • One hidden layer
  • Uses batch normalization and drop out
  • Activation is RELU
  • Optimizer is SGD
  • Loss is MSE

Implementation is based PyTorch except that a user friendly Python wrapper class with a configuration file is used which enables no code model training. After the model is trained all the steps for conformal prediction as outlined earlier are executed. Conformal prediction implementation is in a Python class. Details are in the tutorial document.

Here is the conformal score distribution. The score in this case is absolute error. As expected it has mode around 0 and gradually decreasing with higher score values. The upper confidence bound for tolerance of 0.1 is 46.950.

Here is the final output. There is one row per prediction from the model. The fields in the output are explained below. In all these cases since the predicted values are within the prediction range, they are all accepted

287.419	241.080	333.040	accepted	0.560
312.856	266.160	358.120	accepted	0.560
328.496	282.880	374.840	accepted	0.560
334.895	289.150	381.110	accepted	0.560
298.313	251.530	343.490	accepted	0.560
287.419	241.080	333.040	accepted	0.560
  • Model prediction
  • Prediction range minimum
  • Prediction range maximum
  • Whether prediction is accepted or rejected
  • Efficiency (prediction range as a fraction of maximum range in data)

For this particular problem there is an added advantage with conformal prediction. A human approver makes the final call for the loan amount. To mitigate risk, the human approver could use an amount between model prediction and the prediction range minimum.

There are some important metrics related to conformal prediction for some input as follows.

  • Credibility : Measures how likely the input comes from the same distribution as the training data. it’s the maximum confidence level (or minimum tolerance) which makes the prediction set or range empty. As the confidence level decreases, prediction set or range shrinks
  • Confidence : Measures how certain the model is that the prediction set is a singleton (applicable for classification problem). It’s the maximum confidence level corresponding to the prediction set having one element

Conformal prediction is agnostic to to the underlying machine learning model. It will work equally well for SVM, Random Forest or any other machine learning models.

Wrapping Up

if critical decisions are going to be made based on the machine learning model prediction, then it’s imperative to have a confidence level associated with the prediction. That’s exactly what conformal prediction does. It’s a vital tool in critical decision making systems


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK