mlflow

mlflow.log_param(key, value)

Log the passed-in parameter under the current run, creating a run if necessary.

Parameters:
  • key – Parameter name (string)
  • value – Parameter value (string)
mlflow.log_metric(key, value)

Log the passed-in metric under the current run, creating a run if necessary.

Parameters:
  • key – Metric name (string).
  • value – Metric value (float).
mlflow.log_artifacts(local_dir, artifact_path=None)

Log all the contents of a local directory as artifacts of the run.

mlflow.log_artifact(local_path, artifact_path=None)

Log a local file or directory as an artifact of the currently active run.

mlflow.active_run()

Return the currently active Run, or None if no such run exists.

mlflow.start_run(run_uuid=None, experiment_id=None, source_name=None, source_version=None, entry_point_name=None, source_type=None)

Start a new MLflow run, setting it as the active run under which metrics and params will be logged. The return value can be used as a context manager within a with block; otherwise, end_run() must be called to terminate the current run. If run_uuid is passed or the MLFLOW_RUN_ID environment variable is set, start_run attempts to resume a run with the specified run ID (with run_uuid taking precedence over MLFLOW_RUN_ID), and other parameters are ignored.

Parameters:
  • run_uuid – If specified, get the run with the specified UUID and log metrics and params under that run. The run’s end time is unset and its status is set to running, but the run’s other attributes remain unchanged (the run’s source_version, source_type, etc. are not changed).
  • experiment_id – Used only when run_uuid is unspecified. ID of the experiment under which to create the current run. If unspecified, the run is created under a new experiment with a randomly generated name.
  • source_name – Name of the source file or URI of the project to be associated with the run. Defaults to the current file if none provided.
  • source_version – Optional Git commit hash to associate with the run.
  • entry_point_name – Optional name of the entry point for to the current run.
  • source_type – Integer enum value describing the type of the run (“local”, “project”, etc.). Defaults to mlflow.entities.source_type.SourceType.LOCAL.
Returns:

mlflow.tracking.ActiveRun object that acts as a context manager wrapping the run’s state.

mlflow.end_run(status='FINISHED')
mlflow.get_artifact_uri()

Return the artifact URI of the currently active run. Calls to log_artifact and log_artifacts write artifact(s) to subdirectories of the returned URI.

mlflow.set_tracking_uri(uri)

Set the tracking server URI to the passed-in value. This does not affect the currently active run (if one exists), but takes effect for any successive runs.

The provided URI can be one of three types:

  • An empty string, or a local file path, prefixed with file:/. Data is stored locally at the provided file (or ./mlruns if empty).
  • An HTTP URI like https://my-tracking-server:5000.
  • A Databricks workspace, provided as just the string ‘databricks’ or, to use a specific Databricks profile (per the Databricks CLI), ‘databricks://profileName’.
mlflow.create_experiment(experiment_name)

Create an experiment with the specified name and return its ID.