CoolFace
Apppublic

Kirtan001/R_Bank_Marketing_UCI_Classification

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

End-to-End MLOps: UCI Bank Marketing Analysis

R Tidymodels Shiny Docker CI/CD

This project is a complete MLOps implementation for predicting term deposit subscriptions using the UCI Bank Marketing dataset. It includes data processing, model training (XGBoost), experiment tracking (MLflow), and deployment (Shiny App & Plumber API).

๐Ÿ“‚ Project Structure

โ”œโ”€โ”€ analysis
โ”‚   โ””โ”€โ”€ (EDA and research files)
โ”œโ”€โ”€ data
โ”‚   โ””โ”€โ”€ (Dataset files downloaded automatically)
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ app.R          # Interactive Shiny App for Hugging Face
โ”‚   โ”œโ”€โ”€ plumber.R      # REST API for model serving
โ”‚   โ””โ”€โ”€ model.rds      # Trained model artifact (generated by report)
โ”œโ”€โ”€ tests
โ”‚   โ””โ”€โ”€ (Unit tests for model validation)
โ”œโ”€โ”€ .github/workflows
โ”‚   โ””โ”€โ”€ main.yaml      # CI/CD: Builds & Pushes Docker Image to GHCR
โ”œโ”€โ”€ Dockerfile         # Configuration for containerization
โ”œโ”€โ”€ final_report.Rmd   # Main report: Data -> Training -> Evaluation
โ””โ”€โ”€ README.md          # Project documentation

๐Ÿš€ How to Run

1. Generate the Model

Before running the app or API, you must train the model. Open final_report.Rmd in RStudio and click Knit.

  • โ€”This will run the entire pipeline.
  • โ€”It protects against data leakage.
  • โ€”It saves the best model to src/model.rds.

2. Run Locally (Shiny App)

Open src/app.R in RStudio and click Run App.

3. Run Locally (Plumber API)

Run the following R code:

r
library(plumber)
pr <- plumb("src/plumber.R")
pr$run(port = 8000)

โ˜๏ธ Deployment (Hugging Face Spaces)

This project is configured for Docker deployment on Hugging Face.

Option A: Direct GitHub Connection (Recommended)

  1. 1.Push to GitHub: Commit all files (including src/model.rds) and push to your repository.
  2. 2.Create Space: Go to Hugging Face Spaces -> "Create new Space".
  3. 3.Select SDK: Choose Docker.
  4. 4.Connect Repo: Select your GitHub repository.
  5. 5.Build: Hugging Face will automatically build the Docker image and launch the app.

Option B: Use Pre-Built Image from GitHub Packages (GHCR)

The CI/CD pipeline automatically builds and pushes the Docker image to GitHub Container Registry.

  1. 1.Go to your GitHub Repository -> Packages.
  2. 2.Copy the full image URL (e.g., ghcr.io/username/repo:main).
  3. 3.In Hugging Face Space settings, you can configure it to pull this image (requires Access Token if private).

Option C: Automated CI/CD (GitHub Actions) [Recommended]

We have configured main.yaml to automatically push code improvements to Hugging Face.

  1. 1.Get Token: Go to Hugging Face -> Settings -> Access Tokens -> Create "Write" Token.
  2. 2.Add Secret: Go to GitHub Repo -> Settings -> Secrets and variables -> Actions -> New Repository Secret.
  3. 3.Name: HF_TOKEN
  4. 4.Value: (Paste your token)
  5. 5.Deploy: Any push to main will now auto-update your Space!

๐Ÿค– CI/CD Pipeline

The main.yaml workflow performs the following:

  1. 1.Lints Code: Checks R syntax for errors.
  2. 2.Builds Docker Image: Creates the production container.
  3. 3.Pushes to GHCR: Stores the image in GitHub Packages for easy deployment.

๐Ÿ› ๏ธ Technologies

  • โ€”Modeling: tidymodels, xgboost, ranger, themis (SMOTE).
  • โ€”Deployment: shiny, plumber, docker.
  • โ€”Validation: testthat, yardstick.