This repository contains code to download a fraud detection dataset, train a model, and run an application to predict fraud based on transactions.
For Unix-based systems (Linux, macOS):
sh download.shFor Windows systems, you can manually download the dataset from Kaggle and place it in the fraud_detection directory.
Run the train_model.py script to train the fraud detection model.
python train_model.pyThis script will:
- Load the dataset from
fraudTrain.csv. - Split the data into training and testing sets.
- Train a RandomForest classifier.
- Save the trained model to
fraud_model.pkl.
Run the app.py script to start the Flask application.
python app.pyThis script will:
- Load the trained model.
- Start a Flask web server.
- Provide an endpoint
/predictfor making fraud predictions.
Method: POST
Request Body: JSON object containing the following fields:
cc_numamtziplatlongcity_popunix_timemerch_latmerch_long
Response:
prediction:1if the transaction is predicted to be fraud,0otherwise.
Example request using curl:
curl -X POST http://127.0.0.1:5000/predict -H "Content-Type: application/json" -d '{
"cc_num": "1234567890123456",
"amt": 123.45,
"zip": "12345",
"lat": 40.7128,
"long": -74.0060,
"city_pop": 100000,
"unix_time": 1615158000,
"merch_lat": 40.730610,
"merch_long": -73.935242
}'Response Example:
{
"prediction": 1
}This project is licensed under the MIT License. See the LICENSE file for details.