One of the major pain points for the credit card industry has been to accurately find potential fraudulent transactions and to process them to completion. Every credit card transaction that requires the involvement of a customer service representative costs the company money. Credit card is often a payment method of convenience for the user. The more the genuine transactions get delayed due to checks in place to prevent fraud, the greater is the chance to alienate the consumer. Similarly, credit card firms will need to built a larger customer service workforce to ensure timely processing of transactions.
About the data
The data that has been used as part of this project is from kaggle. Quoting from kaggle, “The datasets contains transactions made by credit cards in September 2013 by european cardholders. This dataset presents transactions that occurred in two days, where we have 492 frauds out of 284,807 transactions. The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions.
It contains only numerical input variables which are the result of a PCA transformation. Unfortunately, due to confidentiality issues, we cannot provide the original features and more background information about the data. Features V1, V2, … V28 are the principal components obtained with PCA, the only features which have not been transformed with PCA are ‘Time’ and ‘Amount’. Feature ‘Time’ contains the seconds elapsed between each transaction and the first transaction in the dataset. The feature ‘Amount’ is the transaction Amount, this feature can be used for example-dependant cost-senstive learning. Feature ‘Class’ is the response variable and it takes value 1 in case of fraud and 0 otherwise.
Given the class imbalance ratio, we recommend measuring the accuracy using the Area Under the Precision-Recall Curve (AUPRC). Confusion matrix accuracy is not meaningful for unbalanced classification.
The dataset has been collected and analysed during a research collaboration of Worldline and the Machine Learning Group (http://mlg.ulb.ac.be) of ULB (Université Libre de Bruxelles) on big data mining and fraud detection. More details on current and past projects on related topics are available on http://mlg.ulb.ac.be/BruFence and http://mlg.ulb.ac.be/ARTML
Please cite: Andrea Dal Pozzolo, Olivier Caelen, Reid A. Johnson and Gianluca Bontempi. Calibrating Probability with Undersampling for Unbalanced Classification. In Symposium on Computational Intelligence and Data Mining (CIDM), IEEE, 2015 "
Loading the data
The Class Column contains 0 or 1 and these numerical levels are converter to a column with two levels. Genuine or Fraud
The data set featured is one that has a highly unbalanced set of data with regards to the class type. 284315 genuine records vs 437 fraudulent ones. In case of unbalanced data, its better to look at precision and recall values to determine if the model is good. Also, from a business stand point, the more the false positives, the more the effort required by customer service to clear it and more the false negatives, more is the danger of losing money due to fraudulent transactions.
There are couple of approaches to solve class imbalance and train a model correctly. We will try various approaches and will see if it helps us to generate a good model.
Tuning parameter 'shrinkage' was held constant at a value of 0.1
Tuning
parameter 'n.minobsinnode' was held constant at a value of 10
Accuracy was used to select the optimal model using the largest value.
The final values used for the model were n.trees = 50, interaction.depth = 3, shrinkage = 0.1
and n.minobsinnode = 10.
x=train_data[, -c(1,31)] # Removing Time and Class
y=train_data$Class
names(x)
grid <- data.frame(fL=c(0,0.5,1.0), usekernel = TRUE, adjust=c(0,0.5,1.0))
model = train(x,y,'nb',trControl=trainControl(method='cv',number=10),tuneGrid=grid)
model
prediction <- predict(model$finalModel,x)
table(prediction$class,y)
naive_ccfraud <- NaiveBayes(ccfraud$Class ~ ., data = ccfraud)
plot(naive_ccfraud)
x=test_data[, -c(1,31)] # Removing Time and Class
y=test_data$Class
prediction <- predict(model$finalModel,x)
table(prediction$class,y)
## Naive Bayes
##
## 199366 samples
## 29 predictor
## 2 classes: '0', '1'
##
## No pre-processing
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 179430, 179430, 179429, 179429, 179429, 179429, ...
## Resampling results across tuning parameters:
##
## fL adjust Accuracy Kappa
## 0.0 0.0 NaN NaN
## 0.5 0.5 0.9978131 0.5481458
## 1.0 1.0 0.9957515 0.3954902
##
## Tuning parameter 'usekernel' was held constant at a value of TRUE
## Accuracy was used to select the optimal model using the largest value.
## The final values used for the model were fL = 0.5, usekernel = TRUE
## and adjust = 0.5.
Technology Enthusiast, with attention to detail, having global exposure. She is a self-motivated problem solver with experience analyzing data and deriving meaningful statistical information. Her goal is to be able to make a positive difference in peoples lives...