Credit Card Fraud Detection ML Methods
Credit Card Fraud Detection ML Methods
June 2022
CREDIT CARD FRAUD DETECTION USING
MACHINE LEARNING METHOD
June 2022
Declaration
It is hereby declared that the work presented in this thesis or any part of this has
not been submitted elsewhere for the award of any degree or diploma
Signatures:
....................................................
(MD. ALAMGIR HOSEN)
.....................................................
([Link] ISLAM)
......................................................
(SUJIT GOMASTA)
All the praises are due to almighty Allah for giving us the ability to complete
this thesis and project. We would like to acknowledge the supports provided by
different people in different aspects of our [Link] of all, we express our
sincere gratitude to our thesis supervisor Dr. Mohammod Abul Kashem,
Professor, Department of Computer Sci- ence and Engineering, DUET,Gazipur,
for providing us time to time advice and instructions in the progression of the re-
search. We are also thankful to him for his insightful review during the editing
and writing of this dissertation. We wish to all the teachers who have directly
or indirectly contributed towards the completion of the thesis work. Last but
not least, we are grateful to our parents and our families for their pa- tience and
support during our studies.
ii
Abstract
Now a days credit card fraud is very serious problem because,use of online bank-
ing and credit card is increasing day by day over the world. As the use of credit
card is increasing, the fraudulent activity also increasing. There are many type of
fraud in credit card. Fraudulent transaction of credit card cause a huge amount
of loss. There are various type of fraud detection technique based on machine
learning algorithm like Neural Network, Logistic Regression, Multi-layer percep-
tron, Random Forest, Nave Bayes, Support Vector Machine etc. Supervised and
unsupervised algorithm apply for credit card fraud detection gives approximate
accurate [Link] this research work we use Logistic Regression ,SGD, K-Nearest
Neighbor, Random Forest, Support Vector Machine, and Naive Bayes Machine
Learning algorithm and we get Random Forest give better perfomance among
them .Then we use fine tune in Random Forest and also use re-sampling tech-
nique on dataset and get result Precision 97%, Recall 97%, F1 score 97% Accuracy
99.98%.
iii
Contents
Declaration i
Acknowledgements ii
Abstract iii
List of Figures vi
List of Tables x
1 Introduction 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Outlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Literature Review 3
2.1 Background Study . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 Credit Card Fraud and Types . . . . . . . . . . . . . . . . 4
2.1.2 Machine learning . . . . . . . . . . . . . . . . . . . . . . . 5
iv
[Link] Unsupervised learning . . . . . . . . . . . . . . . 6
[Link] Reinforcement learning . . . . . . . . . . . . . . 6
[Link] Supervised learning . . . . . . . . . . . . . . . . . 6
2.1.3 Used Algorithm and Technique . . . . . . . . . . . . . . . 7
[Link] Random Forest . . . . . . . . . . . . . . . . . . . 7
[Link] Stochastic Gradient Descent (SGD) . . . . . . . . 9
[Link] Support Vector Machine . . . . . . . . . . . . . . 10
[Link] Naive Bayes . . . . . . . . . . . . . . . . . . . . . 11
[Link] Logistic Regression . . . . . . . . . . . . . . . . 12
[Link] K-nearest Neighbor . . . . . . . . . . . . . . . . 13
[Link] Fine tune parameter . . . . . . . . . . . . . . . . 14
[Link] Re-sampling . . . . . . . . . . . . . . . . . . . . . 15
2.2 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 Methodology 21
3.1 Short description of Methodology . . . . . . . . . . . . . . . . . . 21
3.2 Brief description of Methodology . . . . . . . . . . . . . . . . . . 22
3.2.1 Data-set collection . . . . . . . . . . . . . . . . . . . . . . 22
3.2.2 Exploratory Data Analysis . . . . . . . . . . . . . . . . . 23
3.2.3 Classification Dataset . . . . . . . . . . . . . . . . . . . . . 30
3.2.4 Dataset Prepossessing . . . . . . . . . . . . . . . . . . . . 30
3.2.5 Applying Machine learning algorithm . . . . . . . . . . . 34
3.2.6 Performance evaluation. . . . . . . . . . . . . . . . . . . . 34
3.2.7 Update selected best model . . . . . . . . . . . . . . . . . 35
References 54
Appendix 57
List of Figures
vii
3.9 Probability distribution for V1. . . . . . . . . . . . . . . . . . . . 26
4.22 Precision Recall curve for RF with Fine-Tune and Resampled dataset. 48
4.23 Confusion matrix for RF with Fine-Tune and Class Weight. . . . 49
4.25 Precision Recall curve for RF with Fine-Tune and Class Weight. . 50
2.1 Result[2] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Result[7] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
xi
List of Symbols
P
Summation
σ Standard Daviation
xii
List of Abbreviations
RF Random Forest
SVM Support Vector Machine
NB Naive Bayes
LR Logistic Regression
KNN K-Nearest Neighbour
DL Deep Learning
XGBT Extended Gradient Boosted Tree
NN Neural Networks
QDA Quadratic Discriminated Analysis
HSA Hybrid Supervised Approaches
SGD Stochastic Gradient Descent
ML Machine Learn
SMOTE Synthetic Minority Oversampling Technique
MCC Matthews Correlation
TP True Positive
FP False Positive
TN True Negative
FN False Negative
xiii
Chapter 1
Introduction
1.1 Introduction
In the age of digitization, with the increasing use of e-commerce, use of credit
cards for purchasing goods also exponentially increased. Unfortunately, fraudu-
lent use of credit cards has also become a source of crime. When one or more than
one person directly or indirectly use the money of a victim by fake transactions
and without let the owner know about transaction then this activity is called a
fraud activity. There are two level of fraud:
1. Management level fraud
2. Customer level fraud
1.2 Objective
The fraud detection methodology already have, they use various machine learn-
ing algorithm give approximate accurate [Link] this thesis, the objective is to
analysis previous methods and develop a algorithm with better performance and
accuracy.
1.3 Outlines
Literature Review
At present the prevention of fraud is very important because day by day trans-
action through credit card are [Link] prevention is best way to
reduce fraud, but fraud detection methodologies are therefore necessary if once
prevention is failed [1].In any exchange theft and miss utilization of a credit card
is known as credit card fraud [2].The fraudulent activities impact the business
negatively and the company can loose trust of their customers[a3]. The revenue
and turnover of the company can also be affected [3].The user of credit card can
face financial loss. That’s why credit card transactions need to be analyzed in a
variety of ways to provide more security.
4 2.1. Background Study
Credit card fraud is a broad term basically used to define those fraud which is
committed by using a payment card. It’s occurred when fraud steal a credit card
or illegally obtains a victim’s card details.
There are different types of credit card fraud
1. Lost and Stolen Card Fraud
2. Card not Received Fraud
3. Counterfeit Card Fraud
4. Cardholder not Present Fraud
5. Card ID Theft Fraud
Supervised learning is a machine learning approach where for training the model
use data-set, which is input and output labeled and extract various pattern from
input data. Those patterns are used to solve the unknown [Link] credit card
fraud detection supervised machine learning is a technique that apply algorithm
on both legitimate and fraudulent instance to construct model that can assign
new observations into legitimate or fraudulent class [5]. Supervised learning can
be represented as follows:
Y = f(x)
where x represents the input variables, Y denotes an output variable and f(X) is
a mapping function.
7 2.1. Background Study
Random Forest is one of the most popular supervised machine learning algo-
rithms. In machine learning Random Forest can used for both regression and
classification. To improve the performance and solve complex problem it uses
combination of multiple classifier which is called ensemble learning. From given
dataset Random Forest classifier, takes a number of decision trees on various
8 2.1. Background Study
subset and then it takes the average for improving the predictive accuracy of the
dataset. The greatest number of trees in the forest leads higher accuracy which
prevent overfitting problem.
Step 5: Find prediction of every decision tree for new data and which category
wins majority votes assign new data point to that [8].
SGD is a one kind of classification and regression technique. Its apply for classifi-
cation issue. Therefore its method applies regularized for build an estimator. Its
work well for large scale datatsets and it is an efficient and easy to implements
methods.
Advantage of SGD:
1. Very efficient.
2. Easy to implements and lots of opportunities of code tunning.
Disadvantage of SGD:
1. Requires several hypermeters.
2. Very sensitive for feature scaling.
Bayes’ theorem
Bayes Rule or Bayes law is another name Bayes theorem. To find the probability
of a hypothesis it use prior knowledge.
Formula for Bayes rule as below: -
P (B|A) ∗ P (A)
P (A|B) = (2.1)
P (B)
Where,
P(A—B) It is called Posterior probability, the Probability of hypothesis A on the
observed event B.
P(B—A) It is called Likelihood probability, the Probability of the evidence when
given that, the probability of a hypothesis is true.
P(A) is called Prior [Link] is the Probability of hypothesis before observ-
ing the evidence.
P(B) Probability of Evidence is called Marginal Probability.
1
g(z) = (2.2)
1 + ez
The value of LR cannot go beyond the range 0 and 1, that’s why it forms a “S”
shape curve which is called the Sigmoid function or logistic function. It uses
concept of threshold value, the value above 1 tends to 1 and below 0 tends to 0.
13 2.1. Background Study
Figure 2.5 Before apply K-NN. Figure 2.6 After apply K-NN.
Algorithm of K-NN:
Step 1: Select K the number of neighbors.
Step 2: For K number of neighbors calculate the Euclidian distance.
Step 3: As per distance take K nearest neighbors.
Step 4: From these K nearest neighbors, count the data points number in each
category.
Step 5: Which category has the maximum number of data point, assign the new
data points to that category.
Step 6: End [12].
and top layers. Fine tune slightly adjusts abstract representation of model going
to be reuse, in order to make the model more relevant to the problem [13].
Hyperparameter is a fine-tuning process for Random Forest algorithm. A param-
eter that is set before starting the learning process of a model is called hyperpa-
rameter. They can be manually adjusted. The most used hyperparameters are
1. Number of trees
2. Maximum depth of each tree
3. Bootstrap method
4. The minimum data point needs to split at node
The two most commonly used for choose which hyperparameter should adjust
is exhaustive grid search and validation curve. Validation curve search potential
values of hyperparameter visually, which can optimize. Exhaustive grid searches
every single possible combination of hyperparameter. Advantage of adjusting hy-
perparameter:
1. It improves accuracy of the model.
2. On some dataset, not adjusting the size of trees can be very large since it is
fully grown and unpruned. Adjusting the size and complexity of trees help to
reduce memory consumptions [14].
[Link] Re-sampling
Standard machine learning technique has a bias towards majority class and
they had tendency to ignore minority class. Hence it can have major misclassifi-
cation in minority class than majority class. It can handle by technique below: -
1. Random Over-sampling
2. SMOTE (Synthetic Minority Oversampling Technique)
3. Random Under-Sampling
4. Cluster-based Over Sampling etc.
tor tools. The Visualization techniques used for Carefully choosing appropriate
features and removing the less important one can reduce over-fitting, improve
accuracy and reduce training time. SMOTE is a popular oversampling method
that used when the imbalanced dataset are used .The feature selector tools used
for determined which features are the most important.
In Experiment steps they used some machine learning algorithm. this are Lo-
gistic regression, Naive Bayes,Random forest, Multi-layer perceptron. using this
algorithm they get different type of result.
Sangeeta Mittal,Shivani Tyagi [18], working with popular supervised and un-
supervised machine learning algorithms have been applied to detect credit card
frauds in a highly imbalanced dataset. they found that unsupervised algorithms
handle the dataset skewness in better ways and hence perform well over all met-
rics absolutely and relatively to other techniques.
Vaishnavi Nath Dornadula, Geetha S [19] ,Used popular supervised and un-
supervised machine learning [Link] are Local Outlier factor ,Isolation
forest,Support vector machine(SVM), Logistic regression, Decision tree, Ran-
dom [Link] used one-class SVM which can be best used for binary class
19 2.2. Related Work
[Link] customers are grouped based on their transactions and extract be-
havioural patterns to develop a [Link] cardholders are clustered into different
groups based on their transaction amount. Then using sliding window strategy to
aggregate the transaction made by the cardholders from different groups so that
the behavioural pattern of the groups can be extracted [Link] observed
that the Matthews Correlation Coefficient was the better parameter to deal with
imbalance data-set. By applying the SMOTE, we balanced the [Link] pro-
duced Accuracy, Precision and MCC values before and after applying SMOTE
that show the below:
Table 2.3 Accuracy, Precision and MCC values before applying SMOTE[9]
20 2.2. Related Work
Table 2.4 Accuracy, Precision and MCC values after applying SMOTE[9]
Here from related work we can see that, for detecting fraud in credit card
they only apply machine learning model like Logistic Regression, Random For-
est, Support Vector Machine,Naive Bayes classifier, k Nearest Neighbor, Decision
Tree etc. But they don,t apply any further process to increase its performance.
Major challenges for credit card fraud detection are:
[Link] information: It means majority of transactions (98.9%) are non-
fraud, which make it impossible to identify fraudulent activity.
2. Enormous information: has been stored on even a daily basis as well as the
design construction should be quick enough yet to react properly to a fraud.
[Link] information: It is another major issue because not all fraudulent
activity is captured or recorded.
[Link] methods: Fraudsters also can use Adaptive methods against the sys-
tem.
Chapter 3
Methodology
Credit card payments are one of the most popular forms of electronic payments.
A credit car allows users to purchase goods without having to pay cash. So that
credit card security must be strong and prevent from fraudulent and rightly pro-
vide security must be [Link] procedure start with collecting data set on
credit card fraud. In this research the credit card fraud detection data-set will
be [Link] data preprocessing is done, which can refer to manipulation or
dropping of data before it is used in order to ensure or enhance [Link]
apply various machine learning algorithm. To determine which algorithm is most
suitable for the problem of detecting fraud transaction, different criteria for algo-
rithm comparisons have been used. Most used metrics for determining the results
of machine learning algorithm are accuracy, recall and precision. Lastly, we will
chose method which method providing good and effective result on it.
22 3.2. Brief description of Methodology
For this thesis we chose Some popular machine learning algorithms in supervised
categories to solve the underlying [Link] we will try to solve credit fraud
problem by using a data set called ”[Link]” and various machine learning
algorithm and [Link] Figure 3.1 show the overall proposed methodology.
Our used dataset, ”[Link]” has 284807 rows × 31 columns and we collect
it from [Link] some of the input variables contains financial information,
the PCA transformation of these input variables were performed in order to keep
23 3.2. Brief description of Methodology
The dataset has three of the given features where the PCA transformation is
not apply. Feature ”Time” shows the time between first transaction and the
every other transaction in the dataset. Feature ”Amount” is the amount of the
transactions made by credit card. Feature ”Class” represents the label, and takes
only 2 values: value 1 in case of fraud transaction and 0 [Link] figure:
3.3 show the information about [Link].4 show the visualization of used
dataset using plot.
24 3.2. Brief description of Methodology
In our ”[Link]” dataset there are 284315 non-fraud data and 492 fraud
[Link].5 represent this value as a graph.
25 3.2. Brief description of Methodology
N i(Xi − X)3
P
Skewness = (3.1)
(N − 1) ∗ σ 3
where,Xi is the ith Random Variable. X is the Mean of the Distribution,N is the
Number of Variables in the Distribution, sigma is the Standard Daviation. From
it we get the value in figure: 3.6 and figure: 3.7 : -
26 3.2. Brief description of Methodology
Figure 3.6 Value for Skewness. Figure 3.7 Value for Skewness.
Figure 3.8 Probability distribution for Figure 3.9 Probability distribution for
Time. V1.
27 3.2. Brief description of Methodology
Then we check for null value in dataset and get zero null value there, so we
don’t have to do further [Link] of null value check is shown in figure:
3.21 and figure: 3.22
32 3.2. Brief description of Methodology
Figure 3.21 Null Value Check. Figure 3.22 Null Value Check.
After null value check we detect and filter outlier, Box plots Graphing features
is the easiest way to detect outliers. This can be done using box plots.A box plot
is a standardized graphical representation of a data distribution. It displays five
summary statistics: minimum value, first quartile (Q1), median (Q2), third quar-
tile (Q3) and maximum value.A boxplot is a simple yet effective visualization for
identifying outliers of a variable. Outliers are plotted as points at the endpoints
of the plot. These are the values that are either below (Q1-1.5IQR) or above
(Q3+1.5IQR).
33 3.2. Brief description of Methodology
Figure 3.24 State before filtering Out- Figure 3.25 State after filtering Outlier
lier from Amount. from Amount.
34 3.2. Brief description of Methodology
Since the dataset label is extremely imbalanced, only 0.18% of instances in the
dataset is fraud. Selecting an appropriate evaluation metrics is crucial as standard
metrics work well on balanced dataset. For example, using the accuracy as metrics
for this dataset. The model can just predict all the instances in the dataset as
non-fraud and accuracy of the model still be 99.82%. As 99.82% of the instances
in the dataset is non-fraud. Hence, we need to select ’recall’ and ’f1-score’ as the
metrics to evaluate the model.
TP
Recall = (3.2)
TP + FN
TP + TN
Accuracy = (3.3)
TP + TN + FP + FN
TP
P recision = (3.4)
TP + FP
35 3.2. Brief description of Methodology
2 ∗ P recision ∗ Recall
F 1Score = (3.5)
P recision + Recall
Where,
TP=True Positive
FP=False Positive
TN= True Negative
FN=False Negative
After performance evaluation we select the Best machine learning model from ap-
plied [Link] the perfomance evaluation we get the value recall and f1-score
for every [Link] model which has highest recall and f1-score is considered as
best model.
After selecting best we apply Fine-Tuning Model on the parameter. After fine-
tune, the model has a slightly increase on recall than default parameter.
Then we used the resampling technique on the dataset to make the label bal-
[Link], use the SMOTE to oversample of the minority class. Next, we use
random undersampling to reduce the number of instances of majority class.
We also apply class weight to the [Link] we use fine tuned model along
with resampled dataset and class weighted dataset one after another.
Chapter 4
In our credit card fraud detection thesis, we used the Machine learning model
below: -
[Link] Regression(LR)
[Link] Gradient Descent (SGD)
3.K-nearest Neighbor(K-NN)
[Link] Forest(RF)
[Link] Vector Machine (SVM)
[Link] Bayes(NB)
We also used: -
[Link] Tune
[Link] on Dataset
[Link] weight on Dataset
37 4.1. Experimental Result of various model
From graph of Figure 4.19, we can see that Random Forest model has the
highest Recall And F1 score so we select Random Forest for further process.
ods
Figure 4.20 Confusion matrix for RF with Fine-Tune and Resampled dataset.
48 4.1. Experimental Result of various model
Figure 4.21 Precision, Recall, F1 score and Accuracy for RF with Fine-Tune and
Resampled dataset.
Figure 4.22 Precision Recall curve for RF with Fine-Tune and Resampled dataset.
49 4.1. Experimental Result of various model
Figure 4.23 Confusion matrix for RF with Fine-Tune and Class Weight.
Figure 4.24 Precision, Recall, F1 score and Accuracy for RF with Fine-Tune and
Class Weight.
50 4.2. Comparison
Figure 4.25 Precision Recall curve for RF with Fine-Tune and Class Weight.
4.2 Comparison
Summarising the Random Forest output of previous research work with highest
value and our default parameter Random Forest and Fine-tuned Random Forest
with resampled dataset and dataset with class weight, we get the Table:4.2
In above graph the Random Forest Classifier with Fine-Tuned parameter and
resampled dataset give the best recall so it is the best model. From previous
work done on credit card fraud we can see Random Forest give best performance
with default parameter,which has Precision 96.38%, Recall 81.63%, Accuracy
99.96%.In Preprocessing Dataset we use outlier detection and filtering and feature
[Link] our default parameter Random Forest give Precision 99% Recall
96% F1 score 98% Accuracy 99.986% which is better than previous. Here after
using fine tune to parameter of Random Forest and using re-sampling technique
on dataset get Precision 97%, Recall 97%, F1 score 97% Accuracy 99.98%, where
Recall increase 15.37 % and accuracy increase 0.02%. Since we focus on recall
Random Forest with fine tune and resample dataset is best.
Chapter 5
5.0.1 Conclusion
Credit card frauds describe the very serious business problem. These frauds can
administrate to huge losses in business and personal. For this reason, companies
invest more and more money in developing new ideas and ways that will help to
detect and prevent [Link] that we research this topic to improve the Credit
Card Frauds [Link] previous work done on credit card fraud we can see
Random Forest give best performance with default parameter,which is Precision
96.38%, Recall 81.63%, Accuracy 99.96% .They don,t apply any further process to
increase its [Link] we use fine tune in Random Forest and also use re-
sampling technique on dataset and get result Precision 97%, Recall 97%,F1 score
97%, Accuracy 99.98% where we can see Recall increase 15.37 % and accuracy
increase 0.02%.
53
[3] Megasari Gusandra Saragih, Jacky Chin, Rianti Setyawasih, Phong Thanh
Nguyen, K. [Link] Learning Methods for Analysis Fraud Credit
Card [Link] Journal of Engineering and Advanced Tech-
nology (IJEAT),Volume-8,ISSN: 2249 – 8958, Issue-6S August 2019
[5] Joseph King-Fung [Link] Credit Card Fraud Detection using a Meta-
Learning Strategy,2011.
[8] [Link]
[9] [Link]
algorithm
[10] [Link]
[11] [Link]
[12] [Link]
learning
[13] [Link]
[14] [Link]
and-hyper-parameter-tuning
[15] [Link]
[17] Naresh Kumar Trivedi, Sarita Simaiya ,Umesh Kumar Lilhore, Sanjeev
Kumar [Link] Efficient Credit Card Fraud Detection Model Based on
Machine Learning Methods. International Journal of Advanced Science and
Technology,colume-29, page-3414 - 3424,13 June 2020.
56 References
[18] Vaishnavi Nath Dornadula, Geetha [Link] Card Fraud Detection using Ma-
chine Learning [Link] Computer Science, pages 631–641, 2019.
Python Code:
58
59
60
61
62
63
64
65