A Streamlit-based Machine Learning application that predicts whether a credit card transaction is likely to be fraudulent or legitimate using a hybrid AI pipeline.
Instead of relying on a single machine learning model, this project combines Deep Learning and Traditional Machine Learning to improve feature representation and classification performance.
The workflow consists of:
- Autoencoder (TensorFlow/Keras) for learning compressed latent representations of transaction data.
- Random Forest Classifier (Scikit-learn) that utilizes both the encoded features and contextual transaction features for final fraud prediction.
The application provides an easy-to-use web interface built with Streamlit, making it suitable for demonstrations, portfolio projects, and learning purposes.
- Interactive Streamlit web application
- Hybrid Deep Learning + Machine Learning architecture
- Autoencoder-based feature extraction
- Random Forest fraud classification
- Clean and responsive UI
- Fast prediction with pre-trained models
- Modular project structure
- Separate training and inference pipelines
- Model persistence using Joblib and TensorFlow
- Easily extensible for real-world fraud detection systems
Raw Transaction Features
│
▼
Data Preprocessing
│
▼
Autoencoder Encoder
│
Encoded Features
│
├───────────────┐
│ │
▼ ▼
Contextual Features Encoded Features
│ │
└───────┬───────┘
▼
Feature Concatenation
▼
Random Forest Classifier
▼
Fraud / Legitimate Prediction
.
├── app.py # Streamlit web application
├── utils.py # Model loading and prediction utilities
├── train_and_save.py # Training pipeline
│
├── models/
│ ├── encoder_model.h5
│ ├── hybrid_scaler.joblib
│ ├── rf_hybrid_model.joblib
│ └── feature_means.csv
│
├── notebooks/
│ └── EDA.ipynb # Exploratory Data Analysis
│
├── reports/
│ └── training_report.txt
│
├── requirements.txt
├── README.md
└── creditcard.csv # Dataset (download separately)
The project uses the Credit Card Fraud Detection Dataset available publicly on Kaggle.
Dataset Characteristics:
- Highly imbalanced dataset
- Real-world anonymized transaction data
- PCA-transformed features (
V1–V28) - Additional features:
TimeAmount
- Target Variable:
- 0 → Legitimate Transaction
- 1 → Fraudulent Transaction
Since the dataset is relatively large, it is intentionally excluded from GitHub using .gitignore.
Download the dataset from Kaggle and place it in the project root as:
creditcard.csv
Python 3.11 is recommended for TensorFlow compatibility.
Clone the repository:
git clone https://github.com/yourusername/credit-card-fraud-detection.git
cd credit-card-fraud-detectionCreate a virtual environment:
python -m venv .venvActivate it.
Windows:
.venv\Scripts\activateLinux / Mac:
source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtLaunch the Streamlit app:
streamlit run app.pyThe application will open in your browser and allow you to test transaction fraud predictions interactively.
Train the hybrid model using:
python train_and_save.pyThe training pipeline performs the following steps:
- Loads the dataset
- Cleans and preprocesses the data
- Trains an Autoencoder
- Extracts compressed latent features
- Generates contextual transaction features
- Combines encoded and contextual features
- Trains the Random Forest classifier
- Saves all trained artifacts
Generated artifacts:
models/
│
├── encoder_model.h5
├── hybrid_scaler.joblib
├── rf_hybrid_model.joblib
└── feature_means.csv
reports/
└── training_report.txt
During inference:
- User enters transaction details.
- Input features are standardized.
- The Autoencoder generates compressed feature representations.
- Contextual transaction features are added.
- The Random Forest classifier predicts the transaction class.
- The application displays whether the transaction is likely Fraudulent or Legitimate.
- Python
- Streamlit
- TensorFlow / Keras
- Scikit-learn
- Random Forest
- Autoencoder Neural Network
- Pandas
- NumPy
- Joblib
- Matplotlib
- Seaborn
| File | Purpose |
|---|---|
| encoder_model.h5 | Trained Autoencoder Encoder |
| hybrid_scaler.joblib | Feature scaler |
| rf_hybrid_model.joblib | Random Forest classifier |
| feature_means.csv | Mean values for preprocessing |
The application can be deployed on:
- Streamlit Community Cloud
- Render
- Railway
- Hugging Face Spaces
- Azure App Service
- AWS EC2
Some model files exceed GitHub's 100 MB file size limit.
Install Git LFS:
git lfs installTrack large model files:
git lfs track "models/*.joblib"
git lfs track "models/*.h5"Commit the tracking configuration:
git add .gitattributes
git add models/Some potential enhancements include:
- XGBoost and LightGBM integration
- Explainable AI (SHAP/LIME)
- Real-time fraud detection APIs
- REST API with FastAPI
- Docker containerization
- User authentication
- Transaction history dashboard
- Model monitoring and drift detection
- Hyperparameter optimization
- Cloud deployment with CI/CD pipelines
- This project is intended for educational, demonstration, and portfolio purposes.
- The contextual transaction features used during training are synthetically generated, as they are not available in the original public dataset.
- For real-world deployment, the model should be retrained using actual:
- Merchant information
- Device fingerprints
- Customer behavior
- Geolocation data
- IP address information
- Historical transaction patterns
Narayan Singh
If you found this project useful, consider giving it a ⭐ on GitHub.