Credit_Card_Transactions

Overview

 

Introduction

 

This project analyzes credit card transactions to develop a machine learning model for fraud detection. The project includes data preprocessing, Exploratory Data Analysis, and the development of a Decision Tree model. Model performance is evaluated using accuracy and other key metrics, with feature importance analysis to identify factors contributing to fraud.

 

Data Used

 

The Dataset consists of 1.3 Million credit card transaction records, including various features such as:

The data was downloaded from Kaggle

 

Tools

 

 

Questions

 

 

Skills

 

 

Goals

 

 

Analysis

 

Missing and Duplicated values

 

After validation, no missing or duplicate values were found, allowing us to proceed with Exploratory Data Analysis.

The data was divided into Fraudulent and Not Fraudulent transactions, in order to analize Spending Behavior.

 

Fraudulent Status Distribution

The majority of transactions are labeled as Not Fraudulent.

 

Number of Transactions by State

The majority of Not Fraudulent transactions in the dataset are located in the State of Texas.

 

Spending Behavior

 

Transactions count by Gender Transactions count by Gender

There is a higher count of transactions made by Female customers, as well as a higher amount spent by the same gender.

 

Box Plot of Transaction Amounts

For Not Fraudulent transactions the Average is 67 USD and the Median is 47 USD.

 

Transactions count by Amount Histogram of Transactions Less Than 100

The majority of transactions (82%) are made for charges of less than 100 USD. Furthermore, most of of them are for charges of less than 10 USD.

 

Sum and Count of Fraudulent Transactions by Day Sum of Transaction Amounts by Hour of the Day

Credit cards are predominantly used on Sundays, Mondays, and Saturdays, with the highest usage occurring between 12:00 P.M. and 12:00 A.M.

 

Transaction Amount by Month and Category Sum of Transaction Amounts by Month

Credit Card usage in the U.S. may increase from March to June due to tax refunds, travel, weddings, and spring-related sales. Additionaly, during December when there is a significant boost in credit card use due to holiday shopping, travel, and celebrations.

Both periods coincide with cultural and economic events that encourage higher levels of consumer spending.

 

Transaction count by Category Total Transactions by Category

Credit cards are mainly used at gas and transportation stores, but the transaction amounts are higher at in-person grocery stores.

 

Transaction Amount by Month and Category

The average amount per transaction is twice for at in-person grocery stores, than for gas and transportation stores.

 

Credit Card Fraud Analysis

 

Fraudulent Status Distribution Amount Distribution by Fraudulent Status

Although fraudulent transactions account for only 0.6% of the total number of transactions, they make up over 4% of the total transaction value. This highlights the importance of identifying the features linked to these transactions to more effectively flag them as fraudulent when they occur.

 

Transaction Amount by Month and Category

When analyzing the differences between fraudulent and non-fraudulent transactions, we can see that the spread for non-fraudulent transactions is narrower than that for fraudulent transactions.

 

Histogram of Fraudulent Transaction Amounts

Most of the Fraudulent transactions are for charges of less than 50 USD and in the ranges of 200-400 and 650-1200. In rare ocassions is higher than 1200 USD.

 

Sum of Fraudulent Transaction Amounts by Month

Fraudulent transactions appear to be more frequent in the first half of the year, particularly in May.

 

Sum of Fraudulent Transaction Amounts by Hour Sum and Count of Fraudulent Transactions by Day

There is a notable surge in fraudulent transactions occurring between 10:00 P.M. and 12:00 A.M., especially during the weekends.

 

Fraudulent Transaction count by Category

The number of fraudulent transactions is notably higher in the grocery in-person and online shopping categories. This trend suggests that both physical grocery stores and e-commerce platforms are increasingly vulnerable to fraudulent activities, underscoring the necessity for stronger security measures to protect consumers in these areas.

 

Fraudulent Transaction Amounts by Category

The total value of fraudulent transactions is greatest in the online shopping category, reaching double that of the second highest category, which is in-person shopping. This indicates a concerning trend, as more consumers may be exposed to fraud while making purchases on websites, highlighting the need for enhanced security measures in online transactions.

 

Average Fraudulent Amount per Transaction by Category

The Average of the amount of Fraudulent transactions can be as high as 1,000 USD. The top three categories are: Shopping in websites, Shopping in person and Miscelaneous in website.

 

Machine Learning: Decision Tree

Preprocessing steps:

Results:

The accuracy of the model for the testing data is 0.997; which is considered very high, although, the dataset is imbalanced with more than 99% of the data considered as Not Fraudulent. This can result in misleading conclussions about how accurate the model really is.

ROC Curve

An AUC of 0.88 indicates that the model is effective at distinguishing between Fraudulent and Not Fraudulent transactions, but there is still room for improvement. This is crucial in fraud detection, where misclassifying a small number of fraudulent transactions can have significant consequences.

 

Confusion Matrix

A Confusion Matrix is used to understand the model’s classification capability. Despite having an accuracy of 0.99, the highly imbalanced data causes some concerns when assesing the False Positive and False Negative predictions.

 

Top 10 Important Features

The Decision Tree model provides feature importance scores indicating which features contribute most to predicting fraud. Higher importance scores suggest that these features are more influential in distinguishing Fraudulent from Not Fraudulent transactions.

The Top three features are:

 

Conclusion

This project focused on developing a machine learning model to predict fraudulent credit card transactions, with an emphasis on tackling the challenges posed by a highly imbalanced dataset—where over 99% of the transactions were labeled as Not Fraudulent. This imbalance has the potential to bias the model towards predicting the majority class, leading to under-detection of Fraudulent transactions.

Exploratory Data Analysis (EDA) on Non-Fraudulent Transactions:

As part of the exploratory data analysis (EDA), I examined the spending patterns of Not Fraudulent transactions to gain insights into typical consumer behavior:

Fraudulent Transaction Analysis:

The fraudulent transactions analysis revealed key characteristics:

Model Performance:

The model used for fraud detection is a Decision Tree, which delivered the following performance:

While the model’s high accuracy reflects its ability to correctly classify the majority non-fraudulent class, the AUC of 0.88 highlights its strong capability to distinguish between fraudulent and non-fraudulent transactions, which is essential for effective fraud detection in such imbalanced data.

Recommendations and Next Steps:

By identifying key differences in fraudulent transactions, such as the tendency for smaller amounts and specific time frames, the model provides actionable insights to help financial institutions strengthen fraud detection and safeguard consumer transactions.