Esempio n. 1
0
 def testRaiseErrorWhenMoreThanOneMultiClassKeyAreProvided(self):
     with self.assertRaises(ValueError):
         util.get_plot_data_and_config(
             self._makeTestPlotsData(),
             SingleSliceSpec(features=[(self.column_2, self.slice_c)]),
             top_k=3,
             class_id=0)
Esempio n. 2
0
 def testRaiseErrorWhenBothLabelAndPlotKeyAreProvided(self):
     with self.assertRaises(ValueError):
         util.get_plot_data_and_config(
             self._makeTestPlotsData(),
             SingleSliceSpec(features=[(self.column_2, self.slice_c)]),
             label='head_a',
             output_name='')
Esempio n. 3
0
    def testGetPlotUsingLabel(self):
        data, _ = util.get_plot_data_and_config(
            self._makeTestPlotsData(),
            SingleSliceSpec(features=[(self.column_2, self.slice_c)]),
            label='head_a')

        self.assertEqual(data, self.plots_data_c2['label/head_a'])
Esempio n. 4
0
def render_plot(
    result: view_types.EvalResult,
    slicing_spec: Optional[Union[slicer.SingleSliceSpec,
                                 config_pb2.SlicingSpec]] = None,
    output_name: Optional[Text] = None,
    class_id: Optional[int] = None,
    top_k: Optional[int] = None,
    k: Optional[int] = None,
    label: Optional[Text] = None,
) -> Optional[visualization.PlotViewer]:  # pytype: disable=invalid-annotation
    """Renders the plot view as widget.

  Args:
    result: An tfma.EvalResult.
    slicing_spec: The tfma.SlicingSpec to identify the slice. Show overall if
      unset.
    output_name: A string representing the output name.
    class_id: A number representing the class id if multi class.
    top_k: The k used to compute prediction in the top k position.
    k: The k used to compute prediciton at the kth position.
    label: A partial label used to match a set of plots in the results.

  Returns:
    A PlotViewer 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, cfg = util.get_plot_data_and_config(result.plots, slice_spec_to_use,
                                              output_name, class_id, top_k, k,
                                              label)
    return visualization.render_plot(data, cfg)
Esempio n. 5
0
    def testGetPlotDataAndConfig(self):
        data, eval_config = util.get_plot_data_and_config(
            self._makeTestPlotsData(),
            SingleSliceSpec(features=[(self.column_1, self.slice_a)]))

        self.assertEqual(data, self.plots_data_a)
        self.assertEqual(eval_config['sliceName'], self.column_a)
Esempio n. 6
0
  def testReplaceNaNInPlotWithNone(self):
    data, _ = util.get_plot_data_and_config(
        self._makeTestPlotsData(),
        SingleSliceSpec(features=[(self.column_1, self.slice_c)]))

    self.assertEquals(
        data, {
            metric_keys.CALIBRATION_PLOT_BOUNDARIES: [0.5, None],
            metric_keys.CALIBRATION_PLOT_MATRICES: [[1, 2], [2, None, 3],
                                                    [3, 4]]
        })
Esempio n. 7
0
  def testReplaceNaNInPlotWithNone(self):
    data, _ = util.get_plot_data_and_config(
        self._makeTestPlotsData(),
        SingleSliceSpec(features=[(self.column_1, self.slice_c)]))

    self.assertEqual(data, {
        'calibrationHistogramBuckets': {
            'buckets': [{
                'v': 0.5
            }, {
                'v': None
            }],
        }
    })
Esempio n. 8
0
def render_plot(result, slicing_spec=None):
    """Renders the plot view as widget.

  Args:
    result: An tfma.EvalResult.
    slicing_spec: The slicing spec to identify the slice. Show overall if unset.

  Returns:
    A PlotViewer object if in Jupyter notebook; None if in Colab.
  """
    slice_spec_to_use = slicing_spec if slicing_spec else SingleSliceSpec()
    data, config = util.get_plot_data_and_config(result.plots,
                                                 slice_spec_to_use)
    return visualization.render_plot(data, config)
Esempio n. 9
0
def render_plot(result,
                slicing_spec = None):
  """Renders the plot view as widget.

  Args:
    result: An tfma.EvalResult.
    slicing_spec: The slicing spec to identify the slice. Show overall if unset.

  Returns:
    A PlotViewer object.
  """
  slice_spec_to_use = slicing_spec if slicing_spec else SingleSliceSpec()
  view = tfma_widget.PlotViewer()
  view.data, view.config = util.get_plot_data_and_config(
      result.plots, slice_spec_to_use)

  return view
Esempio n. 10
0
def render_plot(
    result: model_eval_lib.EvalResult,
    slicing_spec: Optional[SingleSliceSpec] = None,
    label: Optional[Text] = None,
) -> Optional[visualization.PlotViewer]:
    """Renders the plot view as widget.

  Args:
    result: An tfma.EvalResult.
    slicing_spec: The slicing spec to identify the slice. Show overall if unset.
    label: A partial label used to match a set of plots in the results.

  Returns:
    A PlotViewer object if in Jupyter notebook; None if in Colab.
  """
    slice_spec_to_use = slicing_spec if slicing_spec else SingleSliceSpec()
    data, config = util.get_plot_data_and_config(result.plots,
                                                 slice_spec_to_use, label)
    return visualization.render_plot(data, config)
Esempio n. 11
0
 def testRaisesErrorWhenMultipleMatchForLabel(self):
     with self.assertRaises(ValueError):
         util.get_plot_data_and_config(
             self._makeTestPlotsData(),
             SingleSliceSpec(features=[(self.column_2, self.slice_c)]),
             label='head_')
Esempio n. 12
0
 def testRaisesErrorWhenLabelNotProvided(self):
     with self.assertRaises(ValueError):
         util.get_plot_data_and_config(
             self._makeTestPlotsData(),
             SingleSliceSpec(features=[(self.column_2, self.slice_c)]))
Esempio n. 13
0
 def testRaisesErrorWhenMultipleSlicesMatchInPlotData(self):
     with self.assertRaises(ValueError):
         util.get_plot_data_and_config(
             self._makeTestPlotsData(),
             SingleSliceSpec(features=[(self.column_1, self.slice_b)]))
Esempio n. 14
0
 def testRaisesErrorWhenNoMatchAvailableInPlotData(self):
     with self.assertRaises(ValueError):
         util.get_plot_data_and_config(
             self._makeTestPlotsData(),
             SingleSliceSpec(features=[(self.column_2, self.slice_a)]))