This repository is a teaching project where you refactor a Jupyter notebook into a reusable Python package (diamonds).
- Python: installed and managed with
pyenv - Virtual environments: managed with
pyenv-virtualenv - direnv: installed and enabled in your shell
-
Clone this repository and move into the project directory.
git clone git@github.com:vivadata/diamonds.git cd diamonds
-
Create a new virtual environment for this project.
pyenv virtualenv 3.11.10 diamonds
-
Tell this directory to use that virtual environment.
pyenv local diamonds -
Check that Python now points to the virtualenv.
which python python --version
-
Allow direnv in this directory (only once).
direnv allow
-
Create an
.envrcfile at the root of the project so the virtualenv is activated automatically when youcdinto the directory.echo 'dotenv' > .envrc direnv allow
-
Leave and re-enter the project directory and confirm that the virtualenv is automatically activated.
cd .. cd Pengouins-demo which python
- Explore the notebook: open
notebooks/Exploration.ipynb. - Identify responsibilities:
- data loading and cleaning,
- feature engineering,
- model training and evaluation,
- prediction.
- Refactor into the package:
- move data-related code into
src/diamonds/data.py, - move model-related code into
src/diamonds/model.py, - centralize constants/paths in
src/diamonds/params.py, - implement model saving/loading in
src/diamonds/registry.py.
- move data-related code into
- Train the model:
- Udpate new script
src/diamonds/train.pyto train the model and save it in themodelsdirectory. - run
python -m src.diamonds.trainto train the model and save it in themodelsdirectory.
- Udpate new script