Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,168 +1,177 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
-
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
- **
|
| 55 |
-
- **
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
- **
|
| 59 |
-
- **
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
**
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
"
|
| 80 |
-
"
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
"
|
| 90 |
-
"
|
| 91 |
-
"
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
#
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
- **
|
| 141 |
-
- **
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
##
|
| 153 |
-
|
| 154 |
-
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
###
|
| 162 |
-
-
|
| 163 |
-
- Check
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
title: Fraud_Detection_using_ML
|
| 4 |
+
sdk: docker
|
| 5 |
+
emoji: π’
|
| 6 |
+
colorFrom: green
|
| 7 |
+
colorTo: red
|
| 8 |
+
pinned: true
|
| 9 |
+
---
|
| 10 |
+
# Fraud Detection System
|
| 11 |
+
|
| 12 |
+
An interactive web application for real-time fraud detection using machine learning.
|
| 13 |
+
|
| 14 |
+
## Features
|
| 15 |
+
|
| 16 |
+
- **Real-time Analysis**: Instant fraud detection with probability scores
|
| 17 |
+
- **Interactive Interface**: User-friendly web interface with Bootstrap styling
|
| 18 |
+
- **Machine Learning**: Random Forest classifier trained on transaction data
|
| 19 |
+
- **Risk Assessment**: 5-level risk classification (Very Low to Very High)
|
| 20 |
+
- **Visual Results**: Progress bars and color-coded risk indicators
|
| 21 |
+
|
| 22 |
+
## Installation
|
| 23 |
+
|
| 24 |
+
1. **Install Python dependencies:**
|
| 25 |
+
```bash
|
| 26 |
+
pip install -r requirements.txt
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
2. **Run the application:**
|
| 30 |
+
```bash
|
| 31 |
+
python app.py
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
3. **Or use the batch file (Windows):**
|
| 35 |
+
```bash
|
| 36 |
+
start_app.bat
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
## Usage
|
| 40 |
+
|
| 41 |
+
1. Open your browser and go to `http://localhost:5000`
|
| 42 |
+
2. Fill in the transaction details:
|
| 43 |
+
- Personal Information (Gender, Age, Location)
|
| 44 |
+
- Account Information (Bank Branch, Account Type, Balance)
|
| 45 |
+
- Transaction Information (Amount, Type, Device, etc.)
|
| 46 |
+
3. Click "Analyze Transaction"
|
| 47 |
+
4. View the fraud probability and risk assessment
|
| 48 |
+
|
| 49 |
+
## Input Fields
|
| 50 |
+
|
| 51 |
+
### Personal Information
|
| 52 |
+
- **Gender**: Female or Male
|
| 53 |
+
- **Age**: Age of the account holder (18-100)
|
| 54 |
+
- **State**: Indian states (Andhra Pradesh to Ladakh)
|
| 55 |
+
- **City**: Major Indian cities (Mumbai, Delhi, Bangalore, etc.)
|
| 56 |
+
|
| 57 |
+
### Account Information
|
| 58 |
+
- **Bank Branch**: Indian bank branches (SBI, HDFC, ICICI, etc.)
|
| 59 |
+
- **Account Type**: Savings, Current, Credit Card, Fixed Deposit, Salary, Joint
|
| 60 |
+
- **Account Balance**: Current account balance in Indian Rupees (βΉ)
|
| 61 |
+
|
| 62 |
+
### Transaction Information
|
| 63 |
+
- **Transaction Amount**: Amount being transacted in Indian Rupees (βΉ)
|
| 64 |
+
- **Transaction Type**: ATM Withdrawal, Bank Deposit, Fund Transfer, UPI Payment, etc.
|
| 65 |
+
- **Transaction Device**: ATM, POS, Mobile Apps, UPI platforms, Internet Banking, etc.
|
| 66 |
+
- **Transaction Date**: Day of month (1-31)
|
| 67 |
+
- **Transaction Time**: Hourly time slots (24-hour format)
|
| 68 |
+
- **Currency**: INR (default), USD, EUR, GBP, AED, SGD, CAD, AUD
|
| 69 |
+
|
| 70 |
+
## API Endpoints
|
| 71 |
+
|
| 72 |
+
### GET /
|
| 73 |
+
Returns the main web interface
|
| 74 |
+
|
| 75 |
+
### POST /predict
|
| 76 |
+
**Request Body:**
|
| 77 |
+
```json
|
| 78 |
+
{
|
| 79 |
+
"gender": "1",
|
| 80 |
+
"age": "35",
|
| 81 |
+
"state": "15",
|
| 82 |
+
"city": "127",
|
| 83 |
+
"bank_branch": "127",
|
| 84 |
+
"account_type": "2",
|
| 85 |
+
"transaction_date": "22",
|
| 86 |
+
"transaction_time": "52151",
|
| 87 |
+
"transaction_amount": "32415.45",
|
| 88 |
+
"transaction_type": "3",
|
| 89 |
+
"account_balance": "74557.27",
|
| 90 |
+
"transaction_device": "17",
|
| 91 |
+
"transaction_currency": "0"
|
| 92 |
+
}
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
**Response:**
|
| 96 |
+
```json
|
| 97 |
+
{
|
| 98 |
+
"prediction": 0,
|
| 99 |
+
"fraud_probability": 15.75,
|
| 100 |
+
"risk_level": "Very Low",
|
| 101 |
+
"risk_color": "#28a745",
|
| 102 |
+
"message": "Legitimate Transaction"
|
| 103 |
+
}
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## Risk Levels
|
| 107 |
+
|
| 108 |
+
- **Very Low** (0-20%): Green (#28a745)
|
| 109 |
+
- **Low** (20-40%): Teal (#20c997)
|
| 110 |
+
- **Medium** (40-60%): Yellow (#ffc107)
|
| 111 |
+
- **High** (60-80%): Orange (#fd7e14)
|
| 112 |
+
- **Very High** (80-100%): Red (#dc3545)
|
| 113 |
+
|
| 114 |
+
## Testing
|
| 115 |
+
|
| 116 |
+
Run the API test script:
|
| 117 |
+
```bash
|
| 118 |
+
python test_api.py
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
## Files Structure
|
| 122 |
+
|
| 123 |
+
```
|
| 124 |
+
fraud_flask_app/
|
| 125 |
+
βββ app.py # Main Flask application
|
| 126 |
+
βββ model.pkl # Trained Random Forest model
|
| 127 |
+
βββ encoders.pkl # Label encoders for categorical features
|
| 128 |
+
βββ requirements.txt # Python dependencies
|
| 129 |
+
βββ start_app.bat # Windows startup script
|
| 130 |
+
βββ test_api.py # API testing script
|
| 131 |
+
βββ templates/
|
| 132 |
+
β βββ index.html # Web interface template
|
| 133 |
+
βββ static/
|
| 134 |
+
β βββ style.css # Custom styling
|
| 135 |
+
βββ README.md # This file
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
## Model Information
|
| 139 |
+
|
| 140 |
+
- **Algorithm**: Random Forest Classifier
|
| 141 |
+
- **Features**: 13 input features
|
| 142 |
+
- **Training Data**: Bank transaction fraud dataset
|
| 143 |
+
- **Performance**: Optimized for fraud detection accuracy
|
| 144 |
+
|
| 145 |
+
## Technologies Used
|
| 146 |
+
|
| 147 |
+
- **Backend**: Flask (Python)
|
| 148 |
+
- **Frontend**: HTML5, CSS3, JavaScript, Bootstrap 5
|
| 149 |
+
- **Machine Learning**: scikit-learn, pandas, numpy
|
| 150 |
+
- **Icons**: Font Awesome
|
| 151 |
+
|
| 152 |
+
## Browser Support
|
| 153 |
+
|
| 154 |
+
- Chrome/Chromium (recommended)
|
| 155 |
+
- Firefox
|
| 156 |
+
- Safari
|
| 157 |
+
- Edge
|
| 158 |
+
|
| 159 |
+
## Troubleshooting
|
| 160 |
+
|
| 161 |
+
### Model Loading Issues
|
| 162 |
+
- Ensure `model.pkl` and `encoders.pkl` are in the same directory as `app.py`
|
| 163 |
+
- Check Python package versions match requirements.txt
|
| 164 |
+
|
| 165 |
+
### Connection Issues
|
| 166 |
+
- Verify Flask is running on port 5000
|
| 167 |
+
- Check firewall settings
|
| 168 |
+
- Ensure no other application is using port 5000
|
| 169 |
+
|
| 170 |
+
### Prediction Errors
|
| 171 |
+
- Validate all input fields are filled correctly
|
| 172 |
+
- Check input value ranges match the specified limits
|
| 173 |
+
- Ensure numeric fields contain valid numbers
|
| 174 |
+
|
| 175 |
+
## License
|
| 176 |
+
|
| 177 |
+
This project is for educational and demonstration purposes.
|