code: def testEvaluateWithSlicingAndUncertainty(self):
      temp_eval_export_dir = self._getEvalExportDir()
      _, eval_export_dir = linear_classifier.simple_linear_classifier(
          None, temp_eval_export_dir
      )
      eval_shared_model = self.createTestEvalSharedModel(
          eval_saved_model_path=eval_export_dir,
          add_metrics_callbacks=[_addExampleCountMetricCallback],
      )
      extractors = [
          legacy_predict_extractor.PredictExtractor(eval_shared_model),
          slice_key_extractor.SliceKeyExtractor(
              [
                  slicer.SingleSliceSpec(),
                  slicer.SingleSliceSpec(columns=["slice_key"]),
              ]
          ),
      ]
  
      for batch_size in [1, 2, 4, 8]:
          with beam.Pipeline() as pipeline:
              example1 = self._makeExample(
                  age=3.0,
                  language="english",
                  label=1.0,
                  slice_key="first_slice",
              )
              example2 = self._makeExample(
                  age=3.0,
                  language="chinese",
                  label=0.0,
                  slice_key="first_slice",
              )
              example3 = self._makeExample(
                  age=4.0,
                  language="english",
                  label=0.0,
                  slice_key="second_slice",
              )
              example4 = self._makeExample(
                  age=5.0,
                  language="chinese",
                  label=1.0,
                  slice_key="second_slice",
              )
              example5 = self._makeExample(
                  age=5.0,
                  language="chinese",
                  label=1.0,
                  slice_key="second_slice",
              )
  
              (metrics, _), _ = (
                  pipeline
                  | "Create"
                  >> beam.Create(
                      [
                          example1.SerializeToString(),
                          example2.SerializeToString(),
                          example3.SerializeToString(),
                          example4.SerializeToString(),
                          example5.SerializeToString(),
                      ]
                  )
                  | "InputsToExtracts"
                  >> model_eval_lib.InputsToExtracts()
                  | "Extract"
                  >> tfma_unit.Extract(
                      extractors=extractors
                  )  # pylint: disable=no-value-for-parameter
                  | "ComputeMetricsAndPlots"
                  >> metrics_and_plots_evaluator._ComputeMetricsAndPlots(
                      eval_shared_model=eval_shared_model,
                      desired_batch_size=batch_size,
                      compute_confidence_intervals=True,
                  )
              )
  
              def check_result(got):
                  try:
                      self.assertEqual(3, len(got), "got: %s" % got)
                      slices = {}
                      for slice_key, value in got:
                          slices[slice_key] = value
                      overall_slice = ()
                      first_slice = (("slice_key", "first_slice"),)
                      second_slice = (("slice_key", "second_slice"),)
                      self.assertCountEqual(
                          list(slices),
                          [overall_slice, first_slice, second_slice],
                      )
                      self.assertDictElementsWithTDistributionAlmostEqual(
                          slices[overall_slice],
                          {
                              "accuracy": 0.4,
                              "label/mean": 0.6,
                              "my_mean_age": 4.0,
                              "my_mean_age_times_label": 2.6,
                              "added_example_count": 5.0,
                          },
                      )
                      self.assertDictElementsWithTDistributionAlmostEqual(
                          slices[first_slice],
                          {
                              "accuracy": 1.0,
                              "label/mean": 0.5,
                              "my_mean_age": 3.0,
                              "my_mean_age_times_label": 1.5,
                              "added_example_count": 2.0,
                          },
                      )
                      self.assertDictElementsWithTDistributionAlmostEqual(
                          slices[second_slice],
                          {
                              "accuracy": 0.0,
                              "label/mean": 2.0 / 3.0,
                              "my_mean_age": 14.0 / 3.0,
                              "my_mean_age_times_label": 10.0 / 3.0,
                              "added_example_count": 3.0,
                          },
                      )
  
                  except AssertionError as err:
                      # This function is redefined every iteration, so it will have the
                      # right value of batch_size.
                      raise util.BeamAssertException(
                          "batch_size = %d, error: %s"
                          % (batch_size, err)
                      )  # pylint: disable=cell-var-from-loop
  
              util.assert_that(metrics, check_result, label="metrics")
  
imports: import os
  import apache_beam
  from apache_beam.testing import util
  import numpy
  import tensorflow
  from tensorflow_model_analysis.api import model_eval_lib
  from tensorflow_model_analysis.api import tfma_unit
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fixed_prediction_estimator
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fixed_prediction_estimator_no_labels
  from tensorflow_model_analysis.eval_saved_model.example_trainers import linear_classifier
  from tensorflow_model_analysis.evaluators import legacy_metrics_and_plots_evaluator
  from tensorflow_model_analysis.extractors import legacy_predict_extractor
  from tensorflow_model_analysis.extractors import slice_key_extractor
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.post_export_metrics import metrics
  from tensorflow_model_analysis.post_export_metrics import post_export_metrics
  from tensorflow_model_analysis.slicer import slicer_lib
label_desc: Use image node_id 5 for calling the EvaluateMetricsAndPlotsTest obj's underlying member method code with example usage: obj.testEvaluateWithSlicingAndUncertainty() without return types