Skip to content

Commit 9bebd2d

Browse files
authored
Merge pull request #25 from billsioros/feat--model-training-&-selection
Model Training & Selection
2 parents eff4822 + 6754119 commit 9bebd2d

25 files changed

+2454
-244
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ indent_size = unset
3030

3131
[*.txt]
3232
indent_size = unset
33+
34+
[*.ipynb]
35+
indent_size = unset

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ POSTGRES_USER='guest'
33
POSTGRES_PASSWORD=')M8z*yss$cRxw7(&'
44

55
BACKEND_DATABASE__URI = 'postgresql://guest:)M8z*yss$cRxw7(&@database:5432/heartbeat'
6+
BACKEND_CHECKPOINT_PATH = './model.joblib'

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,7 @@ Thumbs.db #thumbnail cache on Windows
152152
# End of https://www.toptal.com/developers/gitignore/api/python
153153

154154
*.csv
155+
*.pkl
156+
*.joblib
157+
158+
.vscode

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ repos:
8888
- id: poetry-check
8989
- id: poetry-lock
9090
args: [--check]
91+
- repo: https://github.com/nbQA-dev/nbQA
92+
rev: 1.8.5
93+
hooks:
94+
- id: nbqa-check-ast
95+
- id: nbqa-ruff
96+
- id: nbqa-mypy
9197
- repo: meta
9298
hooks:
9399
- id: check-hooks-apply

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
</a>
4646
</p>
4747

48+
Cardiovascular diseases (CVDs) are the number 1 cause of death globally, taking an estimated 17.9 million lives each year, which accounts for 31% of all deaths worldwide. Four out of 5CVD deaths are due to heart attacks and strokes, and one-third of these deaths occur prematurely in people under 70 years of age. Heart failure is a common event caused by CVDs and this dataset contains 11 features that can be used to predict a possible heart disease.
49+
50+
People with cardiovascular disease or who are at high cardiovascular risk (due to the presence of one or more risk factors such as hypertension, diabetes, hyperlipidaemia or already established disease) need early detection and management wherein a machine learning model can be of great help.
51+
52+
> Source: [https://www.kaggle.com/datasets/fedesoriano/heart-failure-prediction](https://www.kaggle.com/datasets/fedesoriano/heart-failure-prediction)
53+
54+
In this project, we create a complete solution featuring a [`FastAPI`](https://fastapi.tiangolo.com/) backend and a [`React`](https://react.dev/) frontend. We perform Exploratory Data Analysis (EDA) and develop a machine learning model using [`scikit-learn`](https://scikit-learn.org).
55+
4856
## :rocket: Running the project
4957

5058
> [!IMPORTANT]
@@ -65,6 +73,7 @@
6573
POSTGRES_PASSWORD=')M8z*yss$cRxw7(&'
6674
6775
BACKEND_DATABASE__URI = 'postgresql://guest:)M8z*yss$cRxw7(&@database:5432/heartbeat'
76+
BACKEND_CHECKPOINT_PATH = './model.joblib' # The model checkpoint should be in your project directory. This is necessary for mounting the volume in Docker. Leave it as is.
6877
```
6978

7079
3. **Build and start the services** using Docker Compose.
@@ -73,7 +82,7 @@
7382
docker-compose up --build
7483
```
7584

76-
> The frontend and the backend should be now available at [`http://localhost:80`](http://localhost:80) and [`http://localhost:8000`](http://localhost:8000), respectively.
85+
> The frontend and the backend should be now available at [`http://localhost:80`](http://localhost:80) and [`http://localhost:8000`](http://localhost:8000), respectively. Make sure you also run `poe manage database create` to create the actual database (assuming you have correctly exported `BACKEND_DATABASE__URI`).
7786

7887
### Troubleshooting
7988

@@ -97,20 +106,18 @@
97106

98107
### Running the services outside of Docker
99108

100-
> [!IMPORTANT]
101-
> Ensure PostgreSQL is set up before running the project by using `docker compose up database --d`. Afterward, run `poe manage database create` to create the actual database. To tear down PostgreSQL, use `docker compose down database -v`.
102-
103-
Running the backend:
109+
We use the [Poetry](https://python-poetry.org/) Python package manager. [Having installed Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer) you may now create a brand new [virtual environment](https://docs.python.org/3/tutorial/venv.html) and install the project's dependencies.
104110

105111
```shell
106112
export BACKEND_DATABASE__URI='postgresql://guest:)M8z*yss$cRxw7(&@localhost:5432/heartbeat'
113+
export BACKEND_CHECKPOINT_PATH='./model.joblib'
107114
poetry env use 3.11
108115
poetry install
109116
python src/api/app.py
110117
```
111118

112-
> [!NOTE]
113-
> We use the [Poetry](https://python-poetry.org/) Python package manager. [Having installed Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer) you may now create a brand new [virtual environment](https://docs.python.org/3/tutorial/venv.html) and install the project's dependencies.
119+
> [!IMPORTANT]
120+
> Set up PostgreSQL before starting the project with `docker compose up database --d`. Afterward, run `poe manage database create` to create the actual database. To tear down PostgreSQL, use `docker compose down database -v`.
114121

115122
Running the frontend:
116123

@@ -122,12 +129,10 @@ npm run dev -- --host --port 80
122129
```
123130

124131
> [!NOTE]
125-
> [nvm](https://github.com/nvm-sh/nvm) enables you to quickly install and switch between different versions of Node.js via the command line. Ensure you install nvm, then install Node.js 20 by running `nvm install 20`.
132+
> Ensure you have Node.js 20 installed. We use [nvm](https://github.com/nvm-sh/nvm) for this because it makes it easy to install and switch between Node.js versions. To install Node.js 20, run `nvm install 20`.
126133

127134
## :computer: Deploying to production
128135

129-
## Deploying to Production
130-
131136
Deploying to production involves several crucial steps, including setting up a server, configuring DNS, and managing SSL certificates. [`Traefik`](https://github.com/traefik/traefik) simplifies many of these tasks, acting as a powerful reverse proxy and load balancer. For a comprehensive guide on deploying your FastAPI application with Traefik, read the full article [here](https://github.com/tiangolo/blog-posts/blob/master/deploying-fastapi-apps-with-https-powered-by-traefik/README.md).
132137

133138
## :bookmark_tabs: Contributing
@@ -160,4 +165,4 @@ The project's version number and [Changelog](https://github.com/billsioros/heart
160165

161166
## :label: Credits
162167

163-
This project was generated with [`billsioros/heartbeat`](https://github.com/billsioros/heartbeat) cookiecutter template.
168+
This project was generated with [`billsioros/cookiecutter-pypackage`](https://github.com/billsioros/cookiecutter-pypackage) cookiecutter template.

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ services:
3333
interval: 5s
3434
timeout: 10s
3535
retries: 10
36+
volumes:
37+
- ${PWD}/model.joblib:/home/app/app/model.joblib
3638
database:
3739
env_file: .env
3840
container_name: database

0 commit comments

Comments
 (0)