Sitemap

MY PAYPAL

4 min readDec 9, 2022

--

Press enter or click to view image in full size

Hello everyone.Today’s topic is to build a fraud detection model using the provided data set and increase the revenue from transaction fees.

Press enter or click to view image in full size
Today I am in a different image. We will not pay attention.🤫

I’m glad to see you all again. Here we go🚀

1>>Of course, we can start by simply checking the dataset

Press enter or click to view image in full size
We have up to v28 in our dataset.
Press enter or click to view image in full size
Color is positive_green and negative_red

2>>Statistical summary of all the numerical variables in dataset

Press enter or click to view image in full size

3>>Company’s compaingn ids’ composition

Press enter or click to view image in full size
Evidently, data is highly imbalanced. Only 0.173% transactions are fradulent.

4>>Visualizing distributions of all numerical variables

Press enter or click to view image in full size

5>>Time

count    284807.000000
mean 26.337183
std 13.191152
min 0.000000
25% 15.055972
50% 23.525556
75% 38.700139
max 47.997778
Press enter or click to view image in full size
Fraudulent transaction are more evenly distributed than non-fraudulent ones. It looks like fraudulent transactions were relatively lesser at higher time(the seconds elapsed between each transaction and the first transaction)

6>>Distribution of Transaction Amount

Press enter or click to view image in full size
Press enter or click to view image in full size
Transaction Amount

7>>Average transaction Amount for the two classes

Press enter or click to view image in full size

8>>Distribution of transaction amount for the two classes

Press enter or click to view image in full size
It is evident that the average fraudulent transaction amount is greater than the average non-fraudulent transaction amount.

9>>Correlation Matrix

Press enter or click to view image in full size
Press enter or click to view image in full size
There are no multi-colinearity in data. There are no notable correlations between variables. However, we observe some positive correlation between V7 and Amount, and V20 and Amount, and some negative correlation is observed between V2 and Amount, and V3 and Time.

Get Burxon_coder1’s stories in your inbox

Join Medium for free to get updates from this writer.

Press enter or click to view image in full size
Press enter or click to view image in full size
The variables appear to be correlated to some extent. Moving forward to Modelling where we can eliminate these features based on p-values.

Data Modelling🔎

Press enter or click to view image in full size

Let’s groupby our data by “class” first.

Press enter or click to view image in full size

1_Model>>DecisionTreeClassifier

precision    recall  f1-score   support

0 1.00 1.00 1.00 85295
1 0.81 0.74 0.77 148

accuracy 1.00 85443
macro avg 0.90 0.87 0.89 85443
weighted avg 1.00 1.00 1.00 85443

<< 0.9992509626300574 ✅ >>

2_Model<<SVC

              precision    recall  f1-score   support

0 1.00 1.00 1.00 85295
1 0.97 0.57 0.72 148

accuracy 1.00 85443
macro avg 0.98 0.79 0.86 85443
weighted avg 1.00 1.00 1.00 85443

<< 0.9992275552122467 ✅ >>

3_Model>>XGBClassifier

              precision    recall  f1-score   support

0 1.00 1.00 1.00 85295
1 0.91 0.72 0.80 148

accuracy 1.00 85443
macro avg 0.95 0.86 0.90 85443
weighted avg 1.00 1.00 1.00 85443

<< 0.9993914071369217 ✅ >>

4_Model>>RandomForestClassifier

       precision    recall  f1-score   support

0 1.00 1.00 1.00 85295
1 0.95 0.72 0.82 148

accuracy 1.00 85443
macro avg 0.98 0.86 0.91 85443
weighted avg 1.00 1.00 1.00 85443

<< 0.9994499256814484 ✅ >>

5_Model>>LogisticRegression

         precision    recall  f1-score   support

0 1.00 1.00 1.00 85295
1 0.88 0.63 0.73 148

accuracy 1.00 85443
macro avg 0.94 0.81 0.87 85443
weighted avg 1.00 1.00 1.00 85443

<< 0.999204147794436 ✅ >>

Classification summary 🏁

Press enter or click to view image in full size
1_DecisionTreeClassifier << 0.9992509626300574 ✅ >>
2_SVC << 0.9992275552122467 ✅ >>
3_XGBClassifier << 0.9993914071369217 ✅ >>
4_RandomForestClassifier << 0.9994499256814484 ✅ >> 👈👈👈👈👈👈👈👍👍👍👍👍👍👍
5_LogisticRegression << 0.9992041477944436 ✅ >>

We prefer to use the RandomForestClassifier model in this project.Because it works with 99.94% accuracy, which is 00.02% better than the rest.

Many thanks to all

Meme😅
Many thanks to all ✈✈✈

--

--