This tutorial objective is to apply engineering best practices in machine learning development and experimentation using the Kedro framework along with a Kedro's plugin for MLFlow. The information in this README file is limited, as the tutorial video is available here. So if the information here is not enough for you, please check the video (which is in Portuguese).
- 1. Prerequisites
- 2. Setup
- 3. Docker
- 4. Kedro
- 4.1. Check Kedro installation
- 4.2. Create a Kedro Project
- 4.3. Move files properly
- 4.4. Initialize MLFlow plugin
- 4.5 Copy the utils folder from the complete code
- 4.6 Copy the conf folder from the complete code
- 4.7 Copy the notebooks folder from the complete code
- 4.8 Configure your credentials
- 4.9. Run Jupyter Server
- 4.10. Run Kedro Viz
- 5. MLFlow
Follow the instructions here to install Docker Engine for you OS.
Follow the instructions here to install Git for you OS.
Choose the code editor of you preference (PyCharm, Atom, VSCode, etc...) to help you following the tutorial.
mkdir tutorial && cd tutorial
git clone https://github.com/rodra-go/kedro-mlflow-tutorial.git
mkdir follow-trough && cd follow-trough
git init
cp ../kedro-mlflow-tutorial/Dockerfile-zero ./Dockerfile
docker build -t kedro-mlflow-tutorial:0.1 .
docker run --rm --name kedro_mlflow_tutorial -dit -p 4141:4141 -p 8888:8888 -p 5000:5000 -v $(pwd):/usr/src/code/ kedro-mlflow-tutorial:0.1
Replace the $(pwd)
on the command above for the path given by the command pwd
on Windows Power Shell, then run the command.
pwd
on Windows Power Shell, then run the command.
docker run --rm --name kedro_mlflow_tutorial -dit -p 4141:4141 -p 8888:8888 -p 5000:5000 -v <C:/path/to/tutorial/follow-trough>:/usr/src/code/ kedro-mlflow-tutorial:0.1
docker exec -it kedro_mlflow_tutorial bash
kedro info
kedro new
Name your project Kedro MLFlow Tutorial
(otherwise the code might no work).
shopt -s dotglob && mv ./kedro-mlflow-tutorial/* . && rm -rf ./kedro-mlflow-tutorial
kedro mlflow init
cp -R ../kedro-mlflow-tutorial/src/kedro_mlflow_tutorial/utils ./src/kedro_mlflow_tutorial/utils
cp -R ../kedro-mlflow-tutorial/conf ./conf
cp -R ../kedro-mlflow-tutorial/notebooks ./notebooks
In order to access the TPN-USP file server and complete the Data Integration implementation, it is necessary to configure your credentials on TPN-USP Network. Add the following lines to your ./conf/local/credentials.yml
file:
tpn:
username: <your_user_name>
password: <your_password>
In case you don't have access to TPN-USP network, download the raw data here and extract its contents to ./data/01_raw
in your follow-trough directory.
kedro jupyter notebook --ip 0.0.0.0
kedro viz --host 0.0.0.0
mlflow ui --host 0.0.0.0 --backend-store-uri file:///usr/src/code/mlruns
This is your new Kedro project, which was generated using Kedro 0.16.6
.
Take a look at the Kedro documentation to get started.
In order to get the best out of the template:
- Don't remove any lines from the
.gitignore
file we provide - Make sure your results can be reproduced by following a data engineering convention
- Don't commit data to your repository
- Don't commit any credentials or your local configuration to your repository. Keep all your credentials and local configuration in
conf/local/
Declare any dependencies in src/requirements.txt
for pip
installation and src/environment.yml
for conda
installation.
To install them, run:
kedro install
You can run your Kedro project with:
kedro run
Have a look at the file src/tests/test_run.py
for instructions on how to write your tests. You can run your tests as follows:
kedro test
To configure the coverage threshold, go to the .coveragerc
file.
To generate or update the dependency requirements for your project:
kedro build-reqs
This will copy the contents of src/requirements.txt
into a new file src/requirements.in
which will be used as the source for pip-compile
. You can see the output of the resolution by opening src/requirements.txt
.
After this, if you'd like to update your project requirements, please update src/requirements.in
and re-run kedro build-reqs
.
Further information about project dependencies
Note: Using
kedro jupyter
orkedro ipython
to run your notebook provides these variables in scope:context
,catalog
, andstartup_error
.Jupyter, JupyterLab, and IPython are already included in the project requirements by default, so once you have run
kedro install
you will not need to take any extra steps before you use them.
To use Jupyter notebooks in your Kedro project, you need to install Jupyter:
pip install jupyter
After installing Jupyter, you can start a local notebook server:
kedro jupyter notebook
To use JupyterLab, you need to install it:
pip install jupyterlab
You can also start JupyterLab:
kedro jupyter lab
And if you want to run an IPython session:
kedro ipython
You can move notebook code over into a Kedro project structure using a mixture of cell tagging and Kedro CLI commands.
By adding the node
tag to a cell and running the command below, the cell's source code will be copied over to a Python file within src/<package_name>/nodes/
:
kedro jupyter convert <filepath_to_my_notebook>
Note: The name of the Python file matches the name of the original notebook.
Alternatively, you may want to transform all your notebooks in one go. Run the following command to convert all notebook files found in the project root directory and under any of its sub-folders:
kedro jupyter convert --all
To automatically strip out all output cell contents before committing to git
, you can run kedro activate-nbstripout
. This will add a hook in .git/config
which will run nbstripout
before anything is committed to git
.
Note: Your output cells will be retained locally.
Further information about building project documentation and packaging your project