![]() |
VOOZH | about |
The ROC (Receiver Operating Characteristic) curve helps us to visualize the true positive rate or true negative rate of a prediction based on some model. This helps us to assess how well a regression model has fitted the data. The AUC (Area under Curve) of this ROC curve helps us to determine the specificity and sensitivity of the model. The closer the AUC value is to the 1, the better the given model fits the data.
To create the ROC (Receiver Operating Characteristic) curve object in the R Language, we use the roc() function of the pROC package library. The pROC is an R Language package to display and analyze ROC curves. The roc() function takes the actual and predicted value as an argument and returns a ROC curve object as a result. Then, to find the AUC (Area under Curve) of that curve, we use the auc() function. The auc() function takes the roc object as an argument and returns the area under the curve of that roc curve.
Syntax:
roc_object <- roc( response, prediction )
Parameters:
We are calculating the AUC from a ROC curve to evaluate the performance of a logistic regression model using the pROC package.
We are installing and loading the pROC package to enable ROC curve creation and AUC calculation.
We are initializing a sample dataset to train the logistic regression model and evaluate it on test data.
We are training a logistic regression model, making predictions, generating a ROC curve and calculating the AUC value.
Output:
Area under the curve: 0.5
We use the Metrics package in R to compute the AUC-ROC score easily. This package supports a wide range of metrics suitable for regression, classification and time-series models.
We are installing and loading the Metrics package which contains the auc() function for calculating the Area Under the ROC Curve.
We are creating numeric vectors for actual class labels and predicted probabilities of the positive class.
We are using the auc() function from the Metrics package to compute the AUC score based on the actual and predicted values.
Syntax:
auc(actual, predicted)
Parameters:
Output:
0.916666666666667
We use the mltools package in R to calculate the AUC-ROC score and retrieve the ROC curve values. This package is highly optimized for memory and speed and is often used for exploratory data analysis tasks.
We are installing and loading the mltools package, which includes the auc_roc() function to compute AUC and ROC-related statistics.
We are defining two vectors- one for actual binary target values and the other for predicted class probabilities.
We are using auc_roc() from the mltools package to calculate the AUC score and optionally retrieve ROC curve data.
Syntax:
auc_roc(actual, predicted, returnDT)
Parameters:
Output:
0.916666666666667
Output:
The output of auc_roc(predicted, actual) gives the AUC score, which measures the classifier's ability to distinguish between classes. The second output with returnDT = TRUE returns a data table containing ROC curve details like true positive rate (TPR), false positive rate (FPR) and thresholds.