Plotting ROC curve in R Programming
Error metrics allow us to evaluate and justify the model’s performance on a specific dataset. One such error metric is the ROC plot. A classification error metric is the ROC plot, also known as the ROC AUC curve. That is, it assesses the performance and outcomes of classification machine learning algorithms.
To be more specific, the ROC curve represents the value’s probability curve, whereas the AUC is a measure of the separability of different groups of values/labels. The ROC AUC curve can be used to analyze and draw conclusions about how many values have been correctly distinguished and classified by the model based on the labels.
The higher the AUC score, the better the prediction of the predicted values. In technical terms, the ROC curve is the relationship between a model’s True Positive Rate and False Positive Rate. Let us now try to apply the concept of the ROC curve in the following section.
Method 1: Using the plot() function
As previously discussed, we can use ROC plots to evaluate Machine Learning models. So, let us try applying the ROC curve concept to the Logistic Regression model.
In this example, we would model the Bank Loan Defaulter dataset using Logistic Regression. The ROC curve would be plotted using the plot() function from the ‘pROC’ library. The dataset can be found here!
- First, we use the read.csv() function to load the dataset into the environment.
- Prior to modelling, it is critical to split the dataset. As a result, we sample the dataset into training and test data values using the R documentation’s createDataPartition() function.
- To assess the model’s performance, we established error metrics such as Precision, Recall, Accuracy, F1 score, ROC plot, and so on.
- After then, we apply Logistic Regression to our dataset using the R glm() function. The model is then tested on the testing data using the predict() function, and the error metrics are calculated.
- Finally, we compute the roc AUC score for the model using the roc() method and plot it using the plot() function from the ‘pROC’ library.
Link to the used CSV file: bank-loan.
Method 2: Using of the roc.plot() function
To plot the ROC-AUC curve for a model, we can use another library called verification in R programming. To use the function, we must first install and import the verification library into our environment.
After that, we plot the data using the roc.plot() function to get a clear picture of the ‘Sensitivity’ and ‘Specificity’ of the data values, as shown below.