Skip to content

berna14y/MLOps_Final_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ† MLOps Project: Bank Marketing Prediction API


๐Ÿ“ข About

This project was completed as part of the Veri Bilimi Okulu MLOps Bootcamp.
It showcases the end-to-end implementation of a machine learning pipeline, deployment with FastAPI, Docker containerization, and infrastructure automation using Terraform and Ansible on AWS.


๐Ÿ“Œ Problem Statement

Financial institutions often run marketing campaigns to promote term deposit products.
The goal of this project is to predict whether a customer will subscribe to a term deposit using historical campaign data.

This project demonstrates an end-to-end MLOps workflow by building a machine learning pipeline, deploying it via FastAPI, containerizing with Docker, and provisioning infrastructure using Terraform and Ansible on AWS EC2.


๐Ÿ“Š Dataset

  • Source: UCI Machine Learning Repository โ€“ Bank Marketing Dataset
  • File: bank-additional-full.csv
  • Samples: 41,188
  • Features: 21
  • Target: y โ€“ whether the client subscribed to a term deposit (yes / no)

โš™๏ธ Model Pipeline

๐Ÿ”ง Preprocessing

  • Label encoding for categorical variables

๐Ÿง  Feature Engineering

  • contacted_before: derived from pdays
  • age_group: bucketized from age
  • Removed multicollinearity (via correlation matrix + VIF)
  • Feature selection prior to scaling
  • Scaling with RobustScaler

๐Ÿงฎ Modeling

  • VotingClassifier ensemble with:
    • XGBoostClassifier (use_label_encoder=False, eval_metric='logloss')
    • CatBoostClassifier (silent mode)
    • RandomForestClassifier (n_estimators=100)
  • Evaluated using Stratified 5-Fold Cross-Validation
  • Best model saved as voting_model.pkl

๐Ÿ”ข Features Used

['job', 'marital', 'education', 'default', 'housing', 'loan', 'contact', 'month',
 'day_of_week', 'campaign', 'pdays', 'previous', 'poutcome', 'cons.conf.idx',
 'nr.employed', 'age_group']

๐Ÿงช Running Locally

1. Build Docker Image

docker build -t mlops-fastapi -f docker/Dockerfile .

2. Run the API Container

docker run -p 8000:8000 mlops-fastapi

3. Test Prediction

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d @api/test_payload.txt

4. Open Swagger UI

Open your browser and navigate to: http://localhost:8000/docs


โ˜๏ธ Deploy to AWS EC2

1. Provision EC2 Instance with Terraform

cd infra/terraform
terraform init
terraform apply

2. Deploy App with Ansible

cd ../ansible
ansible-playbook -i inventory playbook.yml

๐Ÿ“จ Example Request Payload

{
  "job": "technician",
  "marital": "single",
  "education": "university.degree",
  "default": "no",
  "housing": "yes",
  "loan": "no",
  "contact": "cellular",
  "month": "may",
  "day_of_week": "mon",
  "campaign": 1,
  "pdays": -1,
  "previous": 0,
  "poutcome": "nonexistent",
  "cons_conf_idx": -36.4,
  "nr_employed": 5191.0,
  "age_group": "25-35"
}

๐Ÿ” Drift Detection (Future Scope)

Although drift detection is not implemented in this version, the project is structured for easy integration of drift detection techniques, such as:

  • Statistical monitoring of feature distribution (e.g., using EvidentlyAI)
  • Performance monitoring via accuracy/AUC tracking
  • Triggering retraining when significant drift is detected

๐Ÿ“ Directory Structure

MLOPS_PROJECT/
โ”œโ”€โ”€ api/              # FastAPI implementation
โ”‚   โ”œโ”€โ”€ api_main.py
โ”‚   โ”œโ”€โ”€ predict.py
โ”‚   โ””โ”€โ”€ test_payload.txt
โ”œโ”€โ”€ docker/           # Dockerfile
โ”‚   โ””โ”€โ”€ Dockerfile
โ”œโ”€โ”€ infra/            # Infrastructure as code
โ”‚   โ”œโ”€โ”€ terraform/
โ”‚   โ””โ”€โ”€ ansible/
โ”œโ”€โ”€ ml_model/         # ML logic and training pipeline
โ”‚   โ”œโ”€โ”€ train_model.py
โ”‚   โ”œโ”€โ”€ preprocess.py
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”œโ”€โ”€ EDA.py
โ”‚   โ”œโ”€โ”€ utils.py
โ”‚   โ”œโ”€โ”€ bank-additional-full.csv
โ”‚   โ””โ”€โ”€ saved_models/
โ”œโ”€โ”€ requirements.txt  # Dependencies

๐Ÿ‘ฉโ€๐Ÿ’ป Maintainer

Project by: Berna Yฤฑlmaz
๐Ÿ“ง berna14y@gmail.com


โœ… Summary

This project demonstrates a complete MLOps lifecycle:
From preprocessing and modeling to containerized deployment on AWS infrastructure.
It provides a fast, stateless prediction service and is extensible for further automation, CI/CD, and monitoring.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors