HP Tuning with the Kale JupyterLab Extension

This section will guide you through configuring and running a Katib experiment using the Kale JupyterLab extension.

What You’ll Need

  • An EKF of MiniKF deployment with the default Kale Docker image.

Procedure

  1. Create a new Notebook server using the default Kale Docker image. The image will have the following naming scheme:

    gcr.io/arrikto/jupyter-kale-py38:<IMAGE_TAG>

    Note

    The <IMAGE_TAG> varies based on the MiniKF or EKF release.

  2. Connect to the server, open a terminal, and install scikit-learn:

    $ pip3 install --user scikit-learn==0.23.0
  3. Create a new Jupyter Notebook (that is, an IPYNB file) and enable the Kale extension from the left-side panel.

    ../../../_images/enable-extension.png
  4. Copy and paste the import statements on the top code cell. Tag the cell with the Kale Imports label:

    from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score

    This is how your notebook cell will look like:

    ../../../_images/imports1.png
  5. Copy and paste the following code snippet to a new code cell. Tag the cell with the Kale Pipeline Parameters label:

    C = 1.0

    This is how your notebook cell will look like:

    ../../../_images/pipeline-parameters.png
  6. Copy and paste the following code snippet to a new code cell. Tag the cell with the Kale Pipeline Step label and name it load_data:

    x, y = make_classification(random_state=42)

    This is how your notebook cell will look like:

    ../../../_images/load-data.png
  7. Copy and paste the following code snippet to a new code cell. Tag the cell with the Kale Pipeline Step label and name it process_data. Set the previous step (that is, load_data) as a dependency:

    x, x_test, y, y_test = train_test_split(x, y, test_size=0.1)

    This is how your notebook cell will look like:

    ../../../_images/process-data.png
  8. Copy and paste the following code snippet to a new code cell. Tag the cell with the Kale Pipeline Step label and name it train. Set the previous step (that is, process_data) as a dependency:

    model = LogisticRegression(max_iter=100, C=C) model.fit(x, y)

    This is how your notebook cell will look like:

    ../../../_images/train.png
  9. Copy and paste the following code snippet to a new code cell. Tag the cell with the Kale Pipeline Step label and name it evaluate. Set the previous step (that is, train) as a dependency:

    y_pred = model.predict(x_test) accuracy = accuracy_score(y_test, y_pred)

    This is how your notebook cell will look like:

    ../../../_images/evaluate.png
  10. Print the pipeline’s metric in the last cell of the Notebook. Tag the cell with the Kale pipeline-metrics label:

    print(accuracy)

    This is how your notebook cell will look like:

    ../../../_images/pipeline-metrics.png

    Important

    You should print the metric you care about in the last code cell of your Notebook.

  11. Enable the HP Tuning with Katib option by pressing the corresponding toggle in the Kale extension’s left-side panel:

    ../../../_images/enable-katib.png
  12. Chose the SET UP KATIB JOB button and use the graphical user interface of the extension to configure the experiment:

    ../../../_images/configure.png
  13. Press the COMPILE AND RUN KATIB JOB button located at the bottom of the extension’s left-side panel.

    ../../../_images/button.png

Summary

You have successfully created a Katib experiment using the Kale JupyterLab extension.

What’s Next

Check out the rest of the Kale user guides.