Skip to content

anamitraupadhyay/fraud_detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation


Fraud Detection

This repository contains code to download a fraud detection dataset, train a model, and run an application to predict fraud based on transactions.

Setup Instructions

1. Download the Dataset

For Unix-based systems (Linux, macOS):

sh download.sh

For Windows systems, you can manually download the dataset from Kaggle and place it in the fraud_detection directory.

2. Train the Model

Run the train_model.py script to train the fraud detection model.

python train_model.py

This 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.

3. Run the Application

Run the app.py script to start the Flask application.

python app.py

This script will:

  • Load the trained model.
  • Start a Flask web server.
  • Provide an endpoint /predict for making fraud predictions.

API Usage

Endpoint: /predict

Method: POST

Request Body: JSON object containing the following fields:

  • cc_num
  • amt
  • zip
  • lat
  • long
  • city_pop
  • unix_time
  • merch_lat
  • merch_long

Response:

  • prediction: 1 if the transaction is predicted to be fraud, 0 otherwise.

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
}

License

This project is licensed under the MIT License. See the LICENSE file for details.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published