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.
The Dataset consists of 1.3 Million credit card transaction records, including various features such as:
The data was downloaded from Kaggle
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.

The majority of transactions are labeled as Not Fraudulent.

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

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

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

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.

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.

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.

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

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

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.

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.

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.

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

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

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.

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.

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

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.

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.

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:
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.
As part of the exploratory data analysis (EDA), I examined the spending patterns of Not Fraudulent transactions to gain insights into typical consumer behavior:
The fraudulent transactions analysis revealed key characteristics:
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.
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.