def render_time_series( results: view_types.EvalResults, slicing_spec: Optional[Union[slicer.SingleSliceSpec, config_pb2.SlicingSpec]] = 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. slicing_spec: A tfma.SlicingSpec 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. """ if slicing_spec and isinstance(slicing_spec, config_pb2.SlicingSpec): slicing_spec = slicer.SingleSliceSpec(spec=slicing_spec) slice_spec_to_use = slicing_spec if slicing_spec else slicer.SingleSliceSpec( ) data = util.get_time_series(results, slice_spec_to_use, display_full_path) cfg = { 'isModelCentric': results.get_mode() == constants.MODEL_CENTRIC_MODE } return visualization.render_time_series(data, cfg)
def testDisplayFullPathForTimeSeries(self): data = util.get_time_series(self._makeEvalResults(), SingleSliceSpec(features=[(self.column_2, self.slice_c)]), display_full_path=True) self.assertEqual(len(data), 2) self.assertEqual( data[1]['config'], { 'dataIdentifier': self.full_data_location_2, 'modelIdentifier': self.full_model_location_2 })
def testFilterEvalResultsForTimeSeries(self): data = util.get_time_series(self._makeEvalResults(), SingleSliceSpec(features=[(self.column_2, self.slice_c)]), display_full_path=False) self.assertEqual(len(data), 2) self.assertEqual(data[0]['metrics'], self.metrics_c) self.assertEqual( data[0]['config'], { 'dataIdentifier': self.data_location_1, 'modelIdentifier': self.model_location_1 }) self.assertEqual(data[1]['metrics'], self.metrics_c2) self.assertEqual( data[1]['config'], { 'dataIdentifier': self.base_data_location_2, 'modelIdentifier': self.base_model_location_2 })
def render_time_series(results, slice_spec=None, display_full_path=False): """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)
def testRaisesErrorWhenToomManyMatchesAvailableInTimeSeries(self): with self.assertRaises(ValueError): util.get_time_series(self._makeEvalResults(), SingleSliceSpec(columns=[(self.column_1)]), display_full_path=False)
def testRaisesErrorWhenNoMatchAvailableInTimeSeries(self): with self.assertRaises(ValueError): util.get_time_series(self._makeEvalResults(), SingleSliceSpec(features=[(self.column_2, self.slice_a)]), display_full_path=False)