In Machine Learning, it is very important to have good understanding of different performance metrics. And it is even more important to know when to use which one to correctly explain the model performance. In classification problems more specific to binary classification, you can not conclude your model without plotting Precision-Recall curve and ROC-AUC curve. In this post, will learn what is the main difference between Precision-Recall curve and ROC-AUC curve and when to use which one. Please refer posts Significance of ROC-AUC Curve and Precision vs Recall in case you want to refresh the concepts important for this post.

So before understanding the difference between Precision-recall curve and ROC-AUC curve, lets first understand **why we need Precision-Recall curve and ROC-AUC curve**?.

In classification problem we get predicted probabilities (fraction values in range of 0 to 1) as the model output. Now the next task is to map those probabilities to the classes (o or 1). For that we need some threshold value so that above that threshold we can declare class 1 and below that threshold we can declare as class 0. So now the question is how to decide the optimal threshold.

Here ROC-AUC curve and Precision-Recall curve are two methods to decide the proper threshold values. They are also used to explain the model goodness of fit. Mean how good your model is when it comes to explain the data set.

Now the next important and obvious question is if both of these methods are used for deciding the threshold and explaining model goodness of fit, then why we need both of them? So the answer is both works differently, mean they are highly dependent on target class distribution of the data and domain of the problem.

**Deference between Precision-Recall curve and ROC-AUC curve**

**Precision-Recall Curve **is plotted between precision and recall where precision is on y-axis and recall is on x-axis. It explains the trade-off between positive predictive power (Precision) and True Positive Rate (Recall).

*Just to refresh Precision explains – out of total predicted as positive how many are actual positive hence known as positive predictive power of model. While Recall explains – out of total actual positives how many are predicted as truly positive which is nothing but the true positive rate.*

**True Positive Rate (Recall) = True Positives / (True Positives + False Negatives)**

**Positive Predictive Power (Precision) = True Positives / (True Positives + False Positives)**

If you see the formulas for both precision and recall, you will find that no where they talk about true negatives. And therefore precision and recall are focused in correct prediction of positive class (class of our interest which we define out of the two classes).

In other words, when we have large imbalanced data set mean there are large number of records for one class known as majority class and very few records for other class known as minority class (examples of high imbalance data set could be cancer prediction in medical problems or churn prediction in telecom or any other industry). Then we would be interested in correctly predicting the minority class. Because even a random guess would predict majority class with good amount of accuracy but would be difficult to predict the minority class correctly.

Suppose there are 100 records in your data and 90 records belongs to class 0 and only 10 records belongs to class 1. Hence even a random guess would be 90% accurate in predicting the majority class 0. Therefore, to correctly identify minority classes we use precision and recall related metrics as these two metrics mainly focuses on minority class. **And this minority class we declare as positive class while training the model.**

**Hence to conclude when there is imbalance class distribution in data set, use precision recall curve to explain the model goodness of fit and for threshold detection.**

**ROC-AUC curve **is plotted between True positive rate and false positive rate. True positive rate is put on y-axis where false positive rate is put on x-axis.

**True Positive Rate (Recall) = True Positives / (True Positives + False Negatives)**

**False Positive Rate = False Positives / (False Positives + True Negatives)**

Here in false positive rate formula you see we minimize the false positive rate by maximizing the true negatives and hence true negative mean negative class also being taken in consideration as compared to precision recall curve where we focus only on true positives.

**Hence we can conclude that ROC-AUC curve is used when data set is balanced with respect to target class distribution.**

Hello.

What if we are using weights or a cost matrix to compensate the imbalance?

Will it be still be preferred to use the AUC PR metric?

Or using weights or cost matrix it’s enough and then we can use the AUC ROC curve or even the Accuracy as a metric to optimize our model?

And vice versa, if you use the AUC PR as our metric… do we need to also use weights or cost matrices?

LikeLike