File size: 4,693 Bytes
89b2220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
license: mit
title: Fraud_Detection_using_ML
sdk: docker
emoji: 🏒
colorFrom: green
colorTo: red
pinned: true
---
# Fraud Detection System

An interactive web application for real-time fraud detection using machine learning.

## Features

- **Real-time Analysis**: Instant fraud detection with probability scores
- **Interactive Interface**: User-friendly web interface with Bootstrap styling
- **Machine Learning**: Random Forest classifier trained on transaction data
- **Risk Assessment**: 5-level risk classification (Very Low to Very High)
- **Visual Results**: Progress bars and color-coded risk indicators

## Installation

1. **Install Python dependencies:**
   ```bash
   pip install -r requirements.txt
   ```

2. **Run the application:**
   ```bash
   python app.py
   ```

3. **Or use the batch file (Windows):**
   ```bash
   start_app.bat
   ```

## Usage

1. Open your browser and go to `http://localhost:5000`
2. Fill in the transaction details:
   - Personal Information (Gender, Age, Location)
   - Account Information (Bank Branch, Account Type, Balance)
   - Transaction Information (Amount, Type, Device, etc.)
3. Click "Analyze Transaction"
4. View the fraud probability and risk assessment

## Input Fields

### Personal Information
- **Gender**: Female or Male
- **Age**: Age of the account holder (18-100)
- **State**: Indian states (Andhra Pradesh to Ladakh)
- **City**: Major Indian cities (Mumbai, Delhi, Bangalore, etc.)

### Account Information
- **Bank Branch**: Indian bank branches (SBI, HDFC, ICICI, etc.)
- **Account Type**: Savings, Current, Credit Card, Fixed Deposit, Salary, Joint
- **Account Balance**: Current account balance in Indian Rupees (β‚Ή)

### Transaction Information
- **Transaction Amount**: Amount being transacted in Indian Rupees (β‚Ή)
- **Transaction Type**: ATM Withdrawal, Bank Deposit, Fund Transfer, UPI Payment, etc.
- **Transaction Device**: ATM, POS, Mobile Apps, UPI platforms, Internet Banking, etc.
- **Transaction Date**: Day of month (1-31)
- **Transaction Time**: Hourly time slots (24-hour format)
- **Currency**: INR (default), USD, EUR, GBP, AED, SGD, CAD, AUD

## API Endpoints

### GET /
Returns the main web interface

### POST /predict
**Request Body:**
```json
{
    "gender": "1",
    "age": "35",
    "state": "15",
    "city": "127",
    "bank_branch": "127",
    "account_type": "2",
    "transaction_date": "22",
    "transaction_time": "52151",
    "transaction_amount": "32415.45",
    "transaction_type": "3",
    "account_balance": "74557.27",
    "transaction_device": "17",
    "transaction_currency": "0"
}
```

**Response:**
```json
{
    "prediction": 0,
    "fraud_probability": 15.75,
    "risk_level": "Very Low",
    "risk_color": "#28a745",
    "message": "Legitimate Transaction"
}
```

## Risk Levels

- **Very Low** (0-20%): Green (#28a745)
- **Low** (20-40%): Teal (#20c997)
- **Medium** (40-60%): Yellow (#ffc107)
- **High** (60-80%): Orange (#fd7e14)
- **Very High** (80-100%): Red (#dc3545)

## Testing

Run the API test script:
```bash
python test_api.py
```

## Files Structure

```
fraud_flask_app/
β”œβ”€β”€ app.py                 # Main Flask application
β”œβ”€β”€ model.pkl             # Trained Random Forest model
β”œβ”€β”€ encoders.pkl          # Label encoders for categorical features
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ start_app.bat        # Windows startup script
β”œβ”€β”€ test_api.py          # API testing script
β”œβ”€β”€ templates/
β”‚   └── index.html       # Web interface template
β”œβ”€β”€ static/
β”‚   └── style.css        # Custom styling
└── README.md           # This file
```

## Model Information

- **Algorithm**: Random Forest Classifier
- **Features**: 13 input features
- **Training Data**: Bank transaction fraud dataset
- **Performance**: Optimized for fraud detection accuracy

## Technologies Used

- **Backend**: Flask (Python)
- **Frontend**: HTML5, CSS3, JavaScript, Bootstrap 5
- **Machine Learning**: scikit-learn, pandas, numpy
- **Icons**: Font Awesome

## Browser Support

- Chrome/Chromium (recommended)
- Firefox
- Safari
- Edge

## Troubleshooting

### Model Loading Issues
- Ensure `model.pkl` and `encoders.pkl` are in the same directory as `app.py`
- Check Python package versions match requirements.txt

### Connection Issues
- Verify Flask is running on port 5000
- Check firewall settings
- Ensure no other application is using port 5000

### Prediction Errors
- Validate all input fields are filled correctly
- Check input value ranges match the specified limits
- Ensure numeric fields contain valid numbers

## License

This project is for educational and demonstration purposes.