Giter Site home page Giter Site logo

retention-prediction-demo's Introduction

Retention Prediction for CC-25

๐Ÿ‡ฎ๐Ÿ‡ฉ Part of Bangkit 2022

๐Ÿ›‘ Please use it wisely! Remeber Bangkit 2022 Code of Conduct! Use it as reference only!

Stack used

  1. ๐Ÿค– Tensorflow 2.9
  2. ๐Ÿพ Flask 2.10

Google Cloud Service used

  1. โšก๏ธ Cloud Run

Local requirements

  1. ๐Ÿ Python 3
  2. ๐Ÿณ Docker
  3. ๐Ÿšฆ Any IDE you like

๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป How to use in local

๐Ÿ“’ Notebook

  1. Clone this repositroy
  2. Run python install -r requirements.txt
  3. Open the retention-prediction.ipynb

๐Ÿ”ฅ API (Flask)

Please ignore the expressjs folder. It's my failure ๐Ÿฅฒ

  1. Clone this repositroy
  2. Open flask folder
  3. Run python install -r requirements.txt
  4. Create .env file in root folder with this specifications
Variables Function Example
PORT your_API_port 8081
MODEL_LAYER your_model_layer_path model.json
MODEL_WEIGHTS your_model_weights_path weights.h5
STANDARD_SCALER your_standard_scaler_path (opt) sc.pkl
  1. Run docker build -t retention-pred:v1.0 .
  2. Run export PORT=your_API_port change to match API port
  3. Run docker run --name retention-prediction -p 0.0.0.0:$PORT:$PORT -d retention-pred:v1.0
  4. Test with Postman or CLI

โ˜๏ธ How to use in Cloud

โšก๏ธ Deploy ML API with Cloud Run

โœ… First, let's create our Service account

๐Ÿšจ This still in development. Please jump to the second step

  1. Run export PROJECT_ID=$(gcloud config get-value project)
  2. Run export SA=retention-prediction
  3. Run this to create retention-prediction service account
gcloud iam service-accounts create $SA \
    --description="retention-prediction SA" \
    --display-name="retention-prediction"
  1. Run this to bind service account with Storage Admin role
gcloud projects add-iam-policy-binding $PROJECT_ID \
    --member="serviceAccount:$SA@$PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/storage.admin"
  1. Run this to get service account key as key.json
gcloud iam service-accounts keys create key.json \
    --iam-account=$SA@$PROJECT_ID.iam.gserviceaccount.com
  1. Add s into the .env file
Variables Function Example
GOOGLE_APPLICATION_CREDENTIALS your_service_account_path ./key.json
  1. ๐Ÿšจ Keep it secret okay. Don't push your service account key into the github!

โœ… Then we're ready to deploy our Cloud Run

  1. Run docker build -t gcr.io/$PROJECT_ID/retention-pred:v1.0 .
  2. Run gcloud auth configure-docker and press Y
  3. Run docker push gcr.io/$PROJECT_ID/retention-pred:v1.0
  4. Run gcloud run deploy --image gcr.io/$PROJECT_ID/retention-pred:v1.0 --platform managed
  5. Check your GCP Console > Cloud Run

Misc

  • If you encounter error below, run sudo apt install python3-tk
ModuleNotFoundError: No module named 'tkinter'

References :

[1] https://www.digitalocean.com/community/tutorials/how-to-build-a-deep-learning-model-to-predict-employee-retention-using-keras-and-tensorflow

[2] https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service

retention-prediction-demo's People

Contributors

husni-zuhdi avatar husnizuhdi avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

husnizuhdi

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.