Machine Learning Zoomcamp midterm project: https://github.com/alexeygrigorev/mlbookcamp-code/tree/master/course-zoomcamp/07-midterm-project.
Income classification
Prediction task is to determine whether a person makes over 50K a year.
- https://www.kaggle.com/lodetomasi1995/income-classification
- Copy of the dataset: income_evaluation_dataset.csv
- Colab:https://colab.research.google.com/drive/14O27isuk8rJFNOo_srXqnHl_nuBfa6GE
- copy of the notebook here: notebook.ipynb
Predict if a certain person income is up to 50K using /predict API.
Endpoint:
API:
- /heartbeat
- /predict
curl --location --request POST 'https://ml-zoomcamp-midterm-project.herokuapp.com/predict' \
--header 'Content-Type: application/json' \
--data-raw '{
"age": 45,
"workclass": "private",
"fnlwgt": 209642,
"education": "masters",
"education-num": 14,
"marital-status": "married-civ-spouse",
"occupation": "exec-managerial",
"relationship": "husband",
"race": "white",
"sex": "male",
"capital-gain": 0,
"capital-loss": 0,
"hours-per-week": 45,
"native-country": "italy"
}'
Or download Postman collection: Income Prediction.postman_collection.json
docker build -t income-prediction ./src
docker run -it -p 9696:9696 income-prediction:latest
curl --location --request POST 'http://localhost:9696/predict' \
--header 'Content-Type: application/json' \
--data-raw '{
"age": 45,
"workclass": "private",
"fnlwgt": 209642,
"education": "masters",
"education-num": 14,
"marital-status": "married-civ-spouse",
"occupation": "exec-managerial",
"relationship": "husband",
"race": "white",
"sex": "male",
"capital-gain": 0,
"capital-loss": 0,
"hours-per-week": 45,
"native-country": "italy"
}'
Python required. For more see: https://packaging.python.org/tutorials/installing-packages/.
in /src dir:
pip install pipenv
pipenv install
pipenv shell
python predict.py
Install libomp required by xgboot:
MacOS:
brew install libomp
Ubuntu
RUN apt-get update && apt-get install -y libgomp1
Heroku account needed. Install heroku cli.
Update docker file:
#ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:9696", "predict:app"]
ENTRYPOINT ["gunicorn", "predict:app"]
heroku login
heroku container:login
heroku create your-app-name
heroku container:push web -a your-app-name
heroku container:release web -a your-app-name
Test is up: https://your-app-name-xyz.herokuapp.com/heartbeat
Consume /predict API:
curl --location --request POST 'http://ml-zoomcamp-midterm-project.herokuapp.com/predict' \
--header 'Content-Type: application/json' \
--data-raw '{
"age": 45,
"workclass": "private",
"fnlwgt": 209642,
"education": "masters",
"education-num": 14,
"marital-status": "married-civ-spouse",
"occupation": "exec-managerial",
"relationship": "husband",
"race": "white",
"sex": "male",
"capital-gain": 0,
"capital-loss": 0,
"hours-per-week": 45,
"native-country": "italy"
}'
Download postman collection
and import it in your postman account to run it.