Credit card fraud detection is one of the most challenging anomaly detection problems because fraudulent transactions account for less than 0.2% of all transactions.
This project detects suspicious transactions using Isolation Forest, an unsupervised anomaly detection algorithm that isolates abnormal transactions without relying on fraud labels during training.
Unlike traditional supervised classifiers, Isolation Forest learns the behavior of normal transactions and identifies anomalies based on how easily they are isolated.
The project includes an interactive Streamlit dashboard for:
- Dataset exploration
- Data preprocessing summary
- Fraud detection visualization
- Model performance analysis
- Real-time transaction prediction
- ✅ Real Credit Card Fraud Dataset
- ✅ Isolation Forest Anomaly Detection
- ✅ Hyperparameter Optimization
- ✅ Precision-Recall Evaluation
- ✅ Interactive Streamlit Dashboard
- ✅ Jupyter Notebook
- ✅ Deployment Ready
- ✅ Clean Modular Code Structure
| Technology | Purpose |
|---|---|
| Python | Programming Language |
| Pandas | Data Processing |
| Scikit-Learn | Isolation Forest Model |
| Streamlit | Interactive Dashboard |
| Metric | Value |
|---|---|
| Precision-Recall AUC | 0.2676 |
| F1 Score | 0.3813 |
| Best Hyperparameters | n_estimators=300 |
| Contamination | 0.005 |
| Decision Threshold | 0.0312 |
| Predicted Normal | Predicted Fraud | |
|---|---|---|
| Actual Normal | 56,737 | 127 |
| Actual Fraud | 45 | 53 |
Dataset: Credit Card Fraud Detection Dataset
Source: Kaggle (ULB Machine Learning Group)
https://www.kaggle.com/datasets/mlg-ulb/creditcardfraud
- Total Transactions: 284,807
- Fraudulent Transactions: 492
- Fraud Rate: 0.172%
- Highly Imbalanced Dataset
- PCA-transformed Features (
V1–V28) - Target:
- 0 → Normal
- 1 → Fraud
CreditCard_Fraud_Detection/
├── assets/
│ └── images/
│
├── dataset/
│ └── creditcard.csv
│
├── models/
│ ├── isolation_forest_model.pkl
│ └── evaluation_results.pkl
│
├── notebooks/
│ └── CreditCard_Fraud_Detection.ipynb
│
├── app.py
├── preprocessing.py
├── fraud_detection.py
├── train_model.py
├── utils.py
├── requirements.txt
├── runtime.txt
├── .python-version
├── .gitignore
└── README.md
Clone the repository
git clone YOUR_GITHUB_REPO_URL
cd CreditCard_Fraud_DetectionCreate a virtual environment
python -m venv .venvActivate the virtual environment
.venv\Scripts\activatesource .venv/bin/activateInstall dependencies
pip install -r requirements.txtpython train_model.pyThis will:
- Load the dataset
- Preprocess the data
- Train Isolation Forest
- Save trained model
- Save evaluation metrics
streamlit run app.pyOpen
http://localhost:8501
jupyter notebook notebooks/CreditCard_Fraud_Detection.ipynb- 🏠 Home
- 📂 Dataset Preview
- ⚙️ Data Preprocessing Summary
- 🚨 Fraud Detection Results
- 📈 Model Performance
- 💳 Predict Transaction
This project is fully deployable on Streamlit Community Cloud.
- Push project to GitHub.
- Login to Streamlit Community Cloud.
- Create a new app.
- Select the repository.
- Set:
Main file
app.py
- Deploy.
The application loads the saved model directly and never retrains during startup.
- Improve anomaly threshold calibration
- Add batch CSV prediction
- Add downloadable prediction reports
- Expand hyperparameter search
- Add model monitoring
- Add transaction history visualization
This project is developed for educational and portfolio purposes.






