Skip to content

Cyren4/sda_mlops

Repository files navigation

Banking MLOps : Predicting Loan Defaults in Retail Banking

Context:

We are a new team in the retail banking sector, which is currently experiencing higher-than-expected default rates on personal loans. Personal loans are a significant source of revenue for banks, but they carry the inherent risk that borrowers may default. A default occurs when a borrower stops making the required payments on a debt.

Objective:

The risk team is analyzing the existing loan portfolio to forecast potential future defaults and estimate the expected loss. The primary goal is to build a predictive model that estimates the probability of default for each customer based on their characteristics. Accurate predictions will enable the bank to allocate sufficient capital to cover potential losses, thereby maintaining financial stability.

Access our Deployed Application !

Project Overview report:

Set-up Project

  1. Clone the repository:
git clone https://github.com/Cyren4/sda_mlops.git
cd sda_mlops
  1. Activate virtual env
conda env create -f environment.yml
conda activate banking-mlops
conda env update --file environment.yml --name banking-mlops --prune 
  1. Launch streamlit application :
streamlit run src/app.py
  1. Launch mlflow server and run all cells in the files Mlflow.ipynb to check the mlflow experiments and versions:
mlflow server --host 127.0.0.1 --port 8080

Manual Build and run of Docker Image

  • Build the Docker image:
docker build -t banking-mlops-app .
  • Run the Docker image (NB: streamlit uses the port 8501 but we redirected to 8080)
docker run -p 8080:8080 banking-mlops-app

Comments : This maps port 8501 on your host machine to port 8501 in the container (the port Streamlit uses). You should then be able to access your Streamlit app in your browser at http://localhost:8080.

  • Push this image to dockerhub:
docker login 
docker image tag banking-mlops:latest cramdani/sda_mlops_docker
docker push cramdani/sda_mlops_docker  
docker pull cramdani/sda_mlops_docker

Manual Deployement to Cloud Run

  • Set up environment variable :
export PROJECT_ID=<my-project-id>
export REGION=europe-west1
  • Connect to GCP and set the right project:
gcloud auth login
gcloud config set project $PROJECT_ID
gcloud auth configure-docker $REGION-docker.pkg.dev
  • Build and push the Docker image to Artifact Registry:
# gcloud builds submit --tag  $REGION-docker.pkg.dev/$PROJECT_ID/banking-mlops/mlops-app:latest
gcloud builds submit --tag $REGION-docker.pkg.dev/$PROJECT_ID/banking-mlops-app/mlops-app:latest
  • Deploy the Docker image to Cloud Run:
# gcloud run deploy banking-mlops --image $REGION-docker.pkg.dev/$PROJECT_ID/banking-mlops/mlops-app:latest --region $REGION
gcloud run deploy test-app --image $REGION-docker.pkg.dev/$PROJECT_ID/banking-mlops-app/mlops-app:latest --region europe-west1 --allow-unauthenticated

Automatic Deployement to Cloud Run

  1. Create Service Account on GCP with the admin role for Artifact Registry, Cloud Run and Service Account User:
  1. Add private key for service account (from console or cli) it will give permission to Github Action to push new services to GCP :
gcloud iam service-accounts keys create
  1. Create Secrets in Github Action : (not used yet)
  • Service Account key : GCP_SA_KEY
  • Project ID : GCP_PROJECT_ID
  • Region : GCP_REGION
  • Service Name : GCP_SERVICE_NAME
  1. Create Github Action pipeline in .github/workflows/GCP-cloudrun.yml

  2. Push modification in the main branch

File structure

├── README.md
├── .github/workflows
│   ├── GCP-cloudrun.yml
│   └── github-cicd.yml
├── data
│   ├── feature_importances.csv
│   ├── Loan_Data.csv
│   └── Loan_Data_Preprocessed.csv
├── environment.yml
├── src
│   ├── app.py
│   ├── components
│   │   ├── header.py
│   │   ├── introduction.py
│   │   ├── lstm.py
│   │   ├── perceptron.py
│   │   ├── random_forest.py
│   │   ├── tree.py
│   │   ├── page.py
│   │   └── random_forest.py
│   ├── mlruns/*
│   └── models/*
├── .dockerignore.ipynb
└── .gitignore.ipynb

Contributors

  • Cyrena Ramdani
  • Yoav COHEN
  • Hoang Thuy Duong VU
  • Salma LAHBATI

This project is a student project fulfilling the requirements of a MLOps Course.

Source documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages