{"id":22799123,"url":"https://github.com/thomd/machine-learning-with-fastapi-on-heroku","last_synced_at":"2026-05-06T00:31:53.677Z","repository":{"id":66830087,"uuid":"430127300","full_name":"thomd/machine-learning-with-fastapi-on-heroku","owner":"thomd","description":"Train a machine learning model for FastAPI and deploy on Heroku","archived":false,"fork":false,"pushed_at":"2021-11-20T23:46:49.000Z","size":10611,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T21:42:52.119Z","etag":null,"topics":["heroku","machine-learning","python"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-20T14:39:16.000Z","updated_at":"2022-09-19T11:19:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5828535-8433-490a-a8ec-d2c2c52b5643","html_url":"https://github.com/thomd/machine-learning-with-fastapi-on-heroku","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomd%2Fmachine-learning-with-fastapi-on-heroku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomd%2Fmachine-learning-with-fastapi-on-heroku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomd%2Fmachine-learning-with-fastapi-on-heroku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomd%2Fmachine-learning-with-fastapi-on-heroku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomd","download_url":"https://codeload.github.com/thomd/machine-learning-with-fastapi-on-heroku/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246365651,"owners_count":20765549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heroku","machine-learning","python"],"created_at":"2024-12-12T07:07:57.266Z","updated_at":"2026-05-06T00:31:53.637Z","avatar_url":"https://github.com/thomd.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Train ML Model for FastAPI and Deploy on Heroku\n\n* [FastAPI](https://fastapi.tiangolo.com) is a Web framework for developing RESTful APIs in Python.\n* [Heroku](https://www.heroku.com) is a cloud platform as a service supporting several programming languages.\n\n## Setup\n\nCreate Environment\n\n    conda env create --file environment.yaml\n    conda activate ml-fastapi-heroku\n\n## 1. Data Analysis and Cleaning\n\nData is from the [Pima Indians Diabetes Database](https://data.world/data-society/pima-indians-diabetes-database).\n\nAnalyse and clean the data: [data-analysis.ipynb](./data-analysis.ipynb)\n\nCompare original dataset with cleaned dataset with\n\n    npx daff --www data/original/diabetes.csv data/diabetes.csv\n\n## 2. Train Prediction Model\n\nTraing of a model using a **random forest classifier**: [train-model.ipynb](./train-model.ipynb)\n\nTest model with:\n\n    import pickle\n    model = pickle.load(open('model/model.pkl', 'rb'))\n    p = model.predict_proba([[7,100,72,23,30.5,30.0,0.484,32]])\n    print(p)\n\n## 3. FastAPI Application\n\nFor local testing, start server with\n\n    uvicorn app:app --reload\n\nand open Swagger-UI:\n\n    open http://localhost:8000/docs\n\n## 4. Deploy on Heroku\n\n    pip list --format=freeze \u003e requirements.txt\n    heroku login\n    heroku create predict-diabetes-1\n    git push heroku main\n    heroku ps:scale web=1\n    heroku logs --tail\n    heroku open\n\n## 5. Use API\n\n    curl -s 'https://predict-diabetes-1.herokuapp.com/predict' \\\n         -H 'Content-Type: application/json' \\\n         -d '{\"pregnancies\":1,\"glucose\":89,\"bp\":66,\"skinthickness\":23,\"insulin\":94,\"bmi\":43,\"dpf\":0.167,\"age\":21}'\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomd%2Fmachine-learning-with-fastapi-on-heroku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomd%2Fmachine-learning-with-fastapi-on-heroku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomd%2Fmachine-learning-with-fastapi-on-heroku/lists"}