Sunday, 12 July 2020

ROC Curve and AUC Curve

I am going to explain one of the most advanced topics in machine learning in simple words which is used in Supervised machine learning problem for classification model evaluations purpose.

ROC stands for Reciever Operating Characteristics and AUC stands for Area Under Curve.

To know ROC and AUC first we have to understand Confusion matrix.

A confusion matrix is a table with four box brackets created with combinations of rows and collumns having predicted and actual values. This is a great way to calculate the Precision, Recall, Accuracy, and F-1 Score as well as the AUC-ROC




  • True Positives (TP) : The number of times our model predicted YES and the actual output was also YES or we can say that observation is true and also predicted true.
  • True Negatives (TN): The number of times our model predicted NO and the actual output was NO or we can say that observation is true but predicted false.
  • False Positives (FP): The number of times our model predicted YES and the actual output was NO or we can say that observation is false but predicted true. This is known as a Type 1 Error.
  • False Negatives (FN): The number of times our model predicted NO and the actual output was YES. or we can say that observation is false and also predicted false.This is known as a Type 2 Error.

Precision is equal to number of true positives divided by number of predicted positives.

or in term of confusion matrix:
Means when false positive increases then precision is decreased because denominator will have greater value then numerator.

Recall is equal to number of true positives divided by number of actual total positives.

or in term of confusion matrix:


Means when false negative increases then recall is decreased because denominator will have greater value then numerator.

so we can say that:-

Both  precision  and  recall  range  from  0  to  1  and  a  value  closer  to  1  is  better because in this case numerator and denominator will be equal.

Accuracy is determining out of all the classifications, how many times our model classify it correctly.

Accuracy is equal to sum of number of true positive and true negative is divided by total observations.

or in term of confusion matrix:


This accuracy must be high but this is not best in cases of a imbalanced data set where observations is not equal to each given classes and there is huge differences between number of observations of given classes.

F1 score is a function of precision and recall. It is used to find the correct balance between the precision and recall.

F1 score is  equal to two times product of precision and recall divided by sum of precision and recall.








As  you can see from above figure when precision become equal to zero then recall also become zero and vice-versa, so both must be balanced for best accurate model.

ROC curve means we don't have to create confusion matrix for all threshold value which is used to set threshold of sigmoid function to get best accurate model so to save our time we use ROC curve.

The  ROC curve  will  tell  you  how  the  threshold  impacts  false  positive  rate  and  true  positive rate  and  thus,  in  turn,  false  positives  and  true  positives.

True positive rate(TPR) which  is  the  same  as  recall is equal to true positive divided by sum of true positive and false negative .

False  Positive  Rate(FPR) which  is equal to false positive divided by sum of false positive and true negative.

True  Negative  Rate(TNR)  is known  as  specificity  which is equal to 1  -  FPR.

ROC Curve



X-axis represent false positive rate and y-axis represent true positive rate.

we select best  threshold  from  the  leftmost  top  point  in  the  ROC  curve as shown in above figure.

AUC curve means we don't have to create confusion matrix for all machine learning models like logistics regression, decision tree etc to get best accurate model so to save our time we use AUC curve.

AUC Curve

X-axis represent false positive rate and y-axis represent true positive rate.

we select best AUC Curve having large area under the curve as shown in above figure.


Thank you for more post in simple words related to any topics of artificial intelligence follow my blog and share my blog, if more people follow my blog it will encourage me to make such post regularly. 









3 comments: