O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. First, load the packages and read the credit card dataset:
> library(caret) 
> library(pROC) 
> library(DMwR) 
> library(caTools) 
 
> creditCardData <- read.csv("creditcard.csv") 
  1. Next, change the type of response variable Class from int to factor and then check the number of fraud (1) or normal (0) transaction examples:
> creditCardData$Class<-factor(ifelse(creditCardData$Class==0,"0","1")) 
> table(data$Class) 
     0      1  
284315    492
  1. Now split the dataset into training and test sets and check the dataset target variable proportion:
> splitIndex <- createDataPartition(creditCardData$Class, p = .70, list = FALSE, times = 1) > trainSplit <- creditCardData[ splitIndex,] > table(trainSplit$Class) 0 1 199025 340 > testSplit <- creditCardData[-splitIndex,] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required