mlflow.tracking

class mlflow.tracking.ActiveRun(run_info, store)

Bases: object

Class representing an active run. Has a reference to the store to which state for the run (e.g. run metadata, metrics, parameters, and artifacts) should be persisted.

Contains methods for logging metrics, parameters, etc. under the current run.

Parameters:
  • run_infoRunInfo describing the active run. A corresponding Run object is assumed to already be persisted with state “running” in store.
  • store – Backend store to which the current run should persist state updates.
get_artifact_uri()
get_run()
log_artifact(local_path, artifact_path=None)
log_artifacts(local_dir, artifact_path=None)
log_metric(metric)
log_param(param)
set_terminated(status)
mlflow.tracking.active_run()

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

mlflow.tracking.create_experiment(experiment_name)

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

mlflow.tracking.end_run(status='FINISHED')
mlflow.tracking.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.tracking.get_run(run_uuid)

Return the run with the specified run UUID from the current tracking server.

mlflow.tracking.get_tracking_uri()

Return the current tracking URI. This may not correspond to the tracking URI of the currently active run, since the tracking URI can be updated via set_tracking_uri.

Returns:the tracking URI.
mlflow.tracking.is_local_uri(uri)
mlflow.tracking.list_experiments()

Return a list of all experiments.

mlflow.tracking.log_artifact(local_path, artifact_path=None)

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

mlflow.tracking.log_artifacts(local_dir, artifact_path=None)

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

mlflow.tracking.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.tracking.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.tracking.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.tracking.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.