Giter Club home page Giter Club logo

machine-learning-challenge-lumu's Introduction

Machine Learning Engineer Challenge

Credit Card Fraud Transactions Dataset

The goal of this project is to automate the prediction of fraudulent credit card transacttions, giving a score to them from 0 to 1, being closer to 1 riskiers. The current repository uses a XGBoost model with a grid search approach to find optimal hyperparameters.

How to reproduce the experiment?

Start by pulling the repository.

Then, create a virtual environment using python 3.8 and install the requirements following the next steps (you need to have installed Python 3.8):

virtualenv venv --python=python3.8
source venv/bin/activate
pip install -r requirements.txt

Located in the root of the repository (db-website), execute the following python files in order:

python train/peprocessing.py
python train/eda.py
python train/train.py

The previous commands will preprocess the raw dataset, create the train and test sets, generate the exploratory data analysis and train the model.

How to run the model?

Option 1:

Use the website that I shared to you by email (https://jnge3ehtyv.us-east-1.awsapprunner.com/). The features used in the model are the ones located in the file "./data/variables/vars_raw.json" (MODEL_INPUT). Once the model receive that input, transform the variables to the variables in "FINAL_DATA" to make the predictions.

In the file located at "./test/test.json", there is an example of the body that the model receives. It is important to keep in mind that if any of the variables listed "MODEL_INPUT" is missing or if the type is not the same as indicated in the vars_raw.json file, the service will return an error.

Option 2:

After creating the virtual environment, install the libraries and run:

Then run:

python app.py

This command will rise the web app on the port 8000 of your computer.

Option 3:

Build and run the docker container:

docker build . -t db-website 
docker run --rm -it -p 8000:8000 db-website

How to deploy and how is deployed?

Use the Dockerfile to deploy the container in your cloud of preference. Currently, the model is deployed in a cluster of AWS App Runner, which by default create a Docker container with Python 3.8, copy all the files that are not in the dockerignore, install the requirements, test the health endpoint ("") and deploy the container.

There are currently three endpoints.

  • "/": Health: ensures that the app is deployed and renders the index.html as home of the website
  • "/eda": Exploratory Data Analysis: renders the wda.html generated using sweetviz.
  • "/calculate": Uses the json input to return the explainability of the model using shap, and at the end, the model label, score and version. The threshold used is the one that optimized the F2 score (recall) because the goal is to catch more fraudster transactions sacrifizing a bit the precision.

Insights and how good the model is

According to the shap values located in "./metrics/img/shap.png", it can be noted the most important variables to detect fraud are: the "cashback", "amount", "linea_tc", "interes_tc", "hora", "device_score" and "dcto".

However, the metrics obtained by the test and train set are not very hopeful. As you can see in the "./metrics/test_set_metrics.json" the precision and recall are too low for the suggested threshold, with a tendency to increase the recall as the threshold decreases. In the case of the "./metrics/train_set_metrics.json", the metrics are high, giving us a signal of overfitting.

Next steps

According to the above, for the next steps, I would establish that the following activities should be:

  • To reduce the variance of the test set, we could increase the train dataset, improve the imbalanced dataset by implementing SMOTE, implement regularization techniques

  • Normalize variables and implement feature selection techniques such as Recursive Feature Elimination with Cross Validation.

  • Implement mlflow With Airflow (or kubeflow) for model registry, experiment tracking and monitoring.

machine-learning-challenge-lumu's People

Contributors

dgbaenar avatar

Watchers

 avatar

Forkers

juanchobanano

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.