The receiver operating characteristic area under curve is a way to measure the performance of a classification model, may be created using algorithms like Logistic Regression.
ROC-AUC is basically a graph where we plot true positive rate on y-axis and false positive rate on x-axis.
If a model is good the AUC will be close to 1.
Area Under Curve measures the performance of model better than accuracy because ROC-AUC does not depend on size of test data.
Note that TPR and FPR are defined as below in the context of getting Confusion Matrix plotted.
- True Positive Rate or TPR = It is number of correct positive predictions divided by the total number of positives = TP/(TP+FN)
- False Positive Rate or FPR = It is number of incorrect positive predictions divided by total number of negatives = FP/(TN+FP)
The ROC-AUC plot is used to visualize and represent the performance of the classifier model.
We can print the receiver operating characteristic area under curve using scikit-learn by first importing below libraries.
import matplotlib.pyplot as pyplt from sklearn.metrics import roc_auc_score from sklearn.metrics import roc_curve from sklearn.metrics import auc
Then we need to use below code to print it.
FPR, TPR, thresholds = roc_curve(y_test, y_pred)
ROC_AUC = auc(FPR, TPR)
pyplt.plot(FPR, TPR, color=’black’, label=’AUC = %0.2f’ % ROC_AUC)
pyplt.plot([0, 1], [0, 1], color=’red’, linestyle=’-‘)
pyplt.xlabel(‘False Positive Rate’)
pyplt.ylabel(‘True Positive Rate’)
This code plot below ROC AUC
You can also print the Area Under Curve using below code
I hope you enjoyed this article and can start using some of the techniques described here in your own projects soon.