How to calculate area under the curve in R

This recipe helps you calculate area under the curve in R

Recipe Objective

How to calculate area under the curve in R?

How to calculate the area under the curve in R? Logistic Regression is a classification type supervised learning model. Logistic Regression is used when the independent variable x, can be a continuous or categorical variable, but the dependent variable (y) is a categorical variable. The ROC curve visualizes two metrics of the logistics regression model, TPR — True positive rate and FPR — False positive rate. Plotting all the TPR and FPR values, give a curve known as ROC — Receiver Operator Characteristic curve. The area under the ROC curve is called AUC — Area Under Curve. AUC ranges between 0 and 1 and is used for successful classification of the logistics model. This recipe demonstrates how to calculate area under the curve in R.

Step 1 - Load the necessary libraries

install.packages("pROC") # For ROC curve to evaluate model library(pROC) install.packages('ROCR') library(ROCR)

Step 2 - Define two vectors

For example, defining two vectors, consisting of actual and corresponding predicted values.

actual_values <- c(1,1,1,0,0,0) predict_value <- c(1,0,1,0,1,0)

Step 3 - Plot a ROC curve

ROCR_pred_test <- prediction(predict_value,actual_values) ROCR_perf_test <- performance(ROCR_pred_test,'tpr','fpr') plot(ROCR_perf_test,colorize=TRUE,print.cutoffs.at=seq(0.1,by=0.1))

Step 4 - Calculate the AUC value

AUC values ranges between 0 & 1. A model whose predictions are 100% wrong has an AUC value of 0.0 and a model whose predictions are 100% correct gives an AUC value of 1.0. An AUC 1.0 concludes that the model predicted the values 100% accurately. Hence, the AUC value must be as high as possible.

auc_value <- roc(actual_values, predict_value) auc(auc_value)

"Output the code is :"

0.666666666666667

{"mode":"full","isActive":false}

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

Stock Price Prediction Project using LSTM and RNN
Learn how to predict stock prices using RNN and LSTM models. Understand deep learning concepts and apply them to real-world financial data for accurate forecasting.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.