Example #1
0
def get_time_series(
    results: model_eval_lib.EvalResults, slicing_spec: slicer.SingleSliceSpec,
    display_full_path: bool
) -> List[Dict[Text, Union[Dict[Union[float, Text], Any], Text]]]:
    """Util function that extracts time series data for the specified slice.

  Args:
    results: A collection of EvalResult whose metrics should be visualized in a
      time series.
    slicing_spec: The spec specifying the slice to show in the time series.
    display_full_path: Whether to display the full path or just the file name.

  Returns:
    A list of dictionaries, where each dictionary contains the config and the
    metrics for the specified slice for a single eval run.

  Raises:
    ValueError: if the given slice spec matches more than one slice for any eval
    run in results or if the slicing spec matches nothing in all eval runs.
  """
    data = []
    for result in results.get_results():
        matching_slices = find_all_slices(result.slicing_metrics, slicing_spec)
        slice_count = len(matching_slices)
        if slice_count == 1:
            data.append({
                'metrics': matching_slices[0]['metrics'],
                'config': {
                    'modelIdentifier':
                    _get_identifier(result.config.model_specs[0].location,
                                    display_full_path),
                    'dataIdentifier':
                    _get_identifier(result.config.input_data_specs[0].location,
                                    display_full_path),
                }
            })
        elif slice_count > 1:
            raise ValueError('Given slice spec matches more than one slice.')

    run_count = len(data)
    if not run_count:
        raise ValueError('Given slice spec has no matches in any eval run.')

    return data  # pytype: disable=bad-return-type
Example #2
0
def render_time_series(results: model_eval_lib.EvalResults,
                       slice_spec: Optional[SingleSliceSpec] = None,
                       display_full_path: bool = False
                      ) -> Optional[visualization.TimeSeriesViewer]:  # pytype: disable=invalid-annotation
  """Renders the time series view as widget.

  Args:
    results: An tfma.EvalResults.
    slice_spec: A slicing spec determining the slice to show time series on.
      Show overall if not set.
    display_full_path: Whether to display the full path to model / data in the
      visualization or just show file name.

  Returns:
    A TimeSeriesViewer object if in Jupyter notebook; None if in Colab.
  """
  slice_spec_to_use = slice_spec if slice_spec else SingleSliceSpec()
  data = util.get_time_series(results, slice_spec_to_use, display_full_path)
  config = {
      'isModelCentric': results.get_mode() == constants.MODEL_CENTRIC_MODE
  }

  return visualization.render_time_series(data, config)