MLflow: Basic logging functions

Sumeet Gyanchandani
Analytics Vidhya
Published in
2 min readNov 4, 2019

This is the second article in my MLflow tutorial series:

  1. Setup MLflow in Production
  2. MLflow: Basic logging functions (you are here!)
  3. MLflow logging for TensorFlow
  4. MLflow Projects
  5. Retrieving the best model using Python API for MLflow
  6. Serving a model using MLflow

Let us start with some basic MLflow functions that will help you log various values and artifacts.

import mlflow

Logging functions need to be associated with a particular run. The best way to get everything into a single run is specifying the start of the run at the start of the main function (or some other calling function) and end of the run at the end of the main function.

if __name__ == '__main__':
mlflow.start_run()
#the model code
mlflow.end_run()

mlflow.log_param() logs a single key-value param in the currently active run. The key and value are both strings.

mlflow.log_param('training_steps', training_steps)

mlflow.log_metric() logs a single key-value metric. The value must always be a number.

mlflow.log_metric('accuracy', accuracy)

mlflow.log_artifacts() logs all the files in a given directory as artifacts, taking an optional artifact_path.

mlflow.log_artifacts(export_path, "model")

The above statement will log all the files on the export_path to a directory named “model” inside the artifact directory of the MLflow run.

For more information refer to logging functions.

In the next article, we deeper our understanding of the MLflow logging functions and use them with TensorFlow.

--

--

Sumeet Gyanchandani
Analytics Vidhya

Associate Director at UBS | Former Machine Learning Engineer at Apple, Microsoft Research, Nomoko, Credit Suisse | Master of Science in Artificial Intelligence