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 it works...

First, we read the credit card dataset and verify the number of fraud (492) versus normal (284315) transactions.

After splitting the dataset into training and test sets with a 70/30 ratio using the createDataPartition () method from the caret package, we then apply the SMOTE() method from the DMwR package to generate synthetic data for the minority class (fraud denoted by 1) in the dataset. The perc.over and perc.under attributes of the SMOTE function determine the generation of the number of oversampled and under-sampled data respectively.

Next, we apply a tree-based bagging (treebag) algorithm with 10-fold cross validation to train the model using an artificially created balanced dataset with the SMOTE approach seen earlier. ...

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