Fraud Detection in Financial Transactions by European Cardholders

π Overview
This project presents a complete end-to-end system for detecting fraudulent financial transactions using Machine Learning. It integrates:
- π Automated data pipeline for preprocessing
- π§ Random Forest Classifier and SMOTE optimized for fraud detection
- β‘ FastAPI backend deployed on Render, AWS Lambda for real-time inference
- π» Interactive Streamlit web application hosted on AWS EC2
- π Historical transaction logs for analysis and download
This solution demonstrates expertise in data preprocessing, model training (handling imbalanced data), API development, and Cloud deployment with AWS EC2 & Nginx.
π Features
π Live Demo π http://hadi-fraud-detection.duckdns.org
β
Real Time Fraud Detection in Financial Transactions by European Cardholders
- The model analyzes transactions and provides an instant fraud probability score.
π Transaction History & Export
- Every analyzed transaction is stored in a history log.
- Users can view and download the full history, including fraud probabilities.
π Scalable & Secure Deployment
- Backend hosted on AWS Lambda, Render using FastAPI.
- Frontend powered by Streamlit, deployed on AWS EC2 & Nginx.
π§ Problem Statement
The goal is to detect fraudulent transactions in a dataset of credit card transactions. Financial institutions can use this system to reduce fraud risk and improve their security systems.
Dataset Description
The project uses the Credit Card Fraud Detection dataset from Kaggle, which contains 284,807 credit card transactions, of which 492 are fraudulent. The dataset is highly imbalanced, and the features (V1 to V28) are anonymized, along with the transaction amount.
π Exploratory Data Analysis (EDA)
- Class Distribution: The dataset shows a significant imbalance between normal and fraudulent transactions.
- Amount Distribution: The transaction amount is also analyzed, with a log transformation applied to manage skewness.
π» Modeling
Data Pipeline
- Automated Data Pipeline: Implemented using a YAML configuration file to manage data cleaning, normalization, and log transformation.
- Techniques Used:
- Column Deletion: Removing unnecessary columns (e.g., Time).
- Normalization: Applying standard scaling to continuous features.
- Log Transformation: Transforming the βAmountβ variable to βAmount_Logβ for better handling of skewness.
Model Training
- Random Forest Classifier: Chosen for its robustness and speed in prediction, especially when dealing with imbalanced data.
- Imbalance Handling: SMOTE (Synthetic Minority Over-sampling Technique) was applied to generate synthetic samples for the minority class, improving recall for fraudulent transactions.
Why Random Forest?
Due to the extreme imbalance in the dataset, most models tend to favor the majority class. Random Forest, combined with SMOTE, provides a balanced approach between precision and recall. It achieves high accuracy while ensuring that the minority (fraud) class is adequately represented.
β
Evaluation
The best model was evaluated on the test data, and the following results were obtained
π Deployment
FastAPI API
- Backend: A FastAPI application that serves the model for real-time predictions.
- Deployment: The API is deployed on Render, making it accessible via a public endpoint.
- API URL: https://project-fraud-detection-in-financial.onrender.com/predict
Streamlit Application
- Frontend: An interactive Streamlit app that collects transaction features from the user, sends them to the FastAPI API, and displays the prediction and probability.
- Historical Transactions: The application maintains a history of all analyzed transactions, displaying their fraud probabilities and allowing users to download the transaction history as a CSV file.
- Hosting: The Streamlit app is hosted on AWS EC2 for easy sharing.
- Link: Application-Streamlit : Fraud Detection in Financial Transactions by European Cardholders
βοΈ Installation and Usage
Prerequisites
- Python 3.12
- AWS Account (for deploying the API if needed)
- GitHub Account for hosting the repository
Installation
- Clone the Repository
git clone https://github.com/HadirouTamdamba/Fraud-Detection-in-Financial-Transactions-EU.git
cd Fraud-Detection-in-Financial-Transactions-EU
- Install Dependencies
pip install -r requirements.txt
-
Running the Streamlit Application
Navigate to the Streamlit Directory
Contributing
Contributions are welcome! Please follow these steps:
- Clone the project.
- Create a new branch (feature/new-feature).
- Commit your changes (git commit -m βAdd new featureβ).
- Push the branch (git push origin feature/new-feature).
- Open a Pull Request.
π Conclusion
The Random Forest Classifier combined with SMOTE has proven highly effective for tackling the imbalanced fraud detection problem.
β
Recall score ~0.84 for fraudulent transactions
β
Robust detection of fraudulent activities
β
Scalable & efficient deployment on AWS Lambda & EC2
β
Real-time fraud probability calculation
β
Complete transaction history tracking & export functionality
The deployment of the FastAPI backend on AWS Lambda, Render and the Streamlit web app on AWS EC2 showcases a robust and scalable end-to-end solution. This project highlights advanced skills in Machine Learning, API development, and Cloud Computing.
βοΈ Tech Stack
βοΈ Random Forest Model for fraud detection
βοΈ FastAPI (AWS Lambda) for backend inference
βοΈ Streamlit for interactive UI
βοΈ AWS EC2 & Nginx for cloud deployment
βοΈ Transaction history tracking & CSV export
Acknowledgments
We extend our sincere gratitude to the European financial institutions and data providers that facilitated the collection of transactional data for this project. Their valuable contributions have been instrumental in advancing fraud detection research and enhancing financial security.
A special thanks to all Stakeholders, Researchers, and Contributors who have supported this initiative to make digital transactions safer and more secure for everyone.
π¨βπ» About the Author
Hadirou Tamdamba
AI Engineer Data Scientist Associate | Machine Learning Engineer
π LinkedIn: Hadirou Tamdamba
π GitHub: HadirouTamdamba
π§ Email: hadirou.tamdamba@outlook.fr
π’ Feel free to explore, contribute, or provide feedback!
π Letβs make digital transactions more secure together!