Pipeline metrics

Export and visualize pipeline metrics.

This page shows you how to export metrics from the component. For details about how to build a component, see the guide to building your own component.

Overview of metrics

Kubeflow Pipelines supports scalar metrics exporting. You can write a list of metrics to describe the performance of the model to a local file which will later be uploaded as run-time metrics by the pipeline agent. The uploaded metrics will be visualized in the experiment runs table in the pipeline UI.

Export metrics file

To enable metrics, you need to write a file /mlpipeline-metrics.json. For example:

  accuracy = accuracy_score(df['target'], df['predicted'])
  metrics = {
    'metrics': [{
      'name': 'accuracy-score', # The name of the metric. Visualized as the column name in the runs table.
      'numberValue':  accuracy, # The value of the metric. Must be a numeric value.
      'format': "PERCENTAGE",   # The optional format of the metric. Supported values are "RAW" (displayed in raw format) and "PERCENTAGE" (displayed in percentage format).
  with file_io.FileIO('/mlpipeline-metrics.json', 'w') as f:
    json.dump(metrics, f)

See the full example.

There are several conventions on the metrics file:

  • The file path must be /mlpipeline-metrics.json.
  • The name must follow pattern ^[a-z]([-a-z0-9]{0,62}[a-z0-9])?$.
  • format can only be PERCENTAGE, RAW or not set.
  • numberValue must be a numeric value.

Visualize metrics

To see a visualization of the metrics, open the Experiment runs page in the pipeline UI. The top 3 metrics are displayed as columns for each run. The following example only has one metric named as accuracy-score. Use the Compare runs UI to display the full metrics.

Run metrics