A cutting-edge credit card fraud detection system leveraging three deep learning models: Multilayer Perceptron (MLP), Autoencoder (AE), and Variational Autoencoder (VAE). This system addresses the challenges of highly imbalanced datasets and evolving fraud patterns by combining supervised classification and unsupervised anomaly detection. Deployed via FastAPI for real-time predictions and includes an interactive dashboard.
⭐ Star this repository if you find it useful and share it with others!
- Features
- Dataset
- Project Structure
- Installation
- API Endpoints
- Usage
- Technologies
- Contributing
- License
- Contact
- Three Deep Learning Models:
- MLP: Supervised classifier for direct fraud detection.
- Autoencoder: Unsupervised anomaly detection based on reconstruction errors.
- Variational Autoencoder: Probabilistic model for detecting subtle fraud patterns.
- Robust Preprocessing: Handles imbalanced data with SMOTE and scales features using
RobustScaler. - Real-Time Predictions: FastAPI-based REST API with endpoints for individual and ensemble model predictions.
- Interactive Dashboard: Web interface for testing fraud detection.
- Comprehensive Evaluation: Metrics include Accuracy, Precision, Recall, F1-score, ROC-AUC, and PR-AUC.
- Source: Credit Card Fraud Detection (Kaggle)
- Features: 28 PCA-transformed anonymised features (V1–V28), transaction
Amount, andClass(0 = non-fraudulent, 1 = fraudulent). - Imbalance: Fraudulent transactions ≈ 0.17%.
Three-Model-Deep-Learning-Fraud-Detection-System/
├── app.py # FastAPI application
├── requirements.txt # Project dependencies
├── README.md # Project documentation
├── data/ # Raw dataset (ignored in git)
├── models/ # Trained model files (ignored)
├── saved_models/ # Model checkpoints & scaler (ignored)
├── saved_artifacts/ # Preprocessed data & thresholds (ignored)
├── figures/ # Plots and visualizations (ignored)
├── logs/ # Training & API logs (ignored)
├── notebooks/ # Jupyter notebooks for EDA and experiments
├── tests/ # Unit and integration tests
└── tuner_dir/ # Hyperparameter tuning artifacts
- Python 3.8+
- Git
- Virtual environment (recommended)
-
Clone the Repository:
git clone https://github.com/nafisalawalidris/Three-Model-Deep-Learning-Fraud-Detection-System.git cd Three-Model-Deep-Learning-Fraud-Detection-System -
Create & Activate Virtual Environment:
python -m venv fraud-dl-env
- On Windows (PowerShell):
fraud-dl-env\Scripts\Activate.ps1
- On macOS/Linux:
source fraud-dl-env/bin/activate
- On Windows (PowerShell):
-
Install Dependencies:
pip install -r requirements.txt
-
Run the FastAPI Application:
uvicorn app:app --reload
-
Access the API:
- Swagger UI: http://127.0.0.1:8000/docs
- Dashboard: http://127.0.0.1:8000/dashboard
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Root welcome message |
/health |
GET | API health check |
/models |
GET | List all available models |
/predict/mlp |
POST | Fraud detection using MLP |
/predict/autoencoder |
POST | Fraud detection using Autoencoder |
/predict/vae |
POST | Fraud detection using VAE |
/predict/ensemble |
POST | Fraud detection using ensemble voting |
/dashboard |
GET | Interactive dashboard for predictions |
- Preprocessing: The system handles duplicates, missing values, and scales data using
RobustScaler. SMOTE is applied to address class imbalance. - Training: Models are implemented in PyTorch with dropout, batch normalisation, and early stopping.
- Evaluation: Models are evaluated using Accuracy, Precision, Recall, F1-score, ROC-AUC, and PR-AUC.
- Testing: Use the Swagger UI or cURL to send sample transactions for real-time predictions.
- Language: Python
- Libraries:
- Data:
pandas,numpy - Visualisation:
matplotlib,seaborn - Deep Learning:
torch(PyTorch) - Model Persistence:
joblib,pickle
- Data:
- Deployment: FastAPI
- Version Control: Git + GitHub
Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m 'Add feature' - Push to your branch:
git push origin feature-name
- Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Portfolio: https://nafisalawalidris.github.io/13/
- GitHub: nafisalawalidris
- Email: Reach out for inquiries or collaboration.