code: def _EvaluateMetricsAndPlots(  # pylint: disable=invalid-name
      extracts: beam.pvalue.PCollection,
      eval_shared_model: types.EvalSharedModel,
      desired_batch_size: Optional[int] = None,
      metrics_key: str = constants.METRICS_KEY,
      plots_key: str = constants.PLOTS_KEY,
      compute_confidence_intervals: Optional[bool] = False,
      min_slice_size: int = 1,
      serialize: bool = False,
      random_seed_for_testing: Optional[int] = None,
  ) -> evaluator.Evaluation:
      """Evaluates metrics and plots using the EvalSavedModel.
  
      Args:
        extracts: PCollection of Extracts. The extracts MUST contain a
          FeaturesPredictionsLabels extract keyed by
          tfma.FEATURE_PREDICTION_LABELS_KEY and a list of SliceKeyType extracts
          keyed by tfma.SLICE_KEY_TYPES_KEY. Typically these will be added by
          calling the default_extractors function.
        eval_shared_model: Shared model parameters for EvalSavedModel including any
          additional metrics (see EvalSharedModel for more information on how to
          configure additional metrics).
        desired_batch_size: Optional batch size for batching in Aggregate.
        metrics_key: Name to use for metrics key in Evaluation output.
        plots_key: Name to use for plots key in Evaluation output.
        compute_confidence_intervals: Whether or not to compute confidence
          intervals.
        min_slice_size: If the number of examples in a specific slice is less
          than min_slice_size, then an error will be returned for that slice.
          This will be useful to ensure privacy by not displaying the aggregated
          data for smaller number of examples.
        serialize: If true, serialize the metrics to protos as part of the
          evaluation as well.
        random_seed_for_testing: Provide for deterministic tests only.
  
      Returns:
        Evaluation containing metrics and plots dictionaries keyed by 'metrics'
        and 'plots'.
      """
      # pylint: disable=no-value-for-parameter
  
      (metrics, plots), slices_count = (
          extracts
          | "ComputeMetricsAndPlots"
          >> _ComputeMetricsAndPlots(
              eval_shared_model,
              desired_batch_size,
              compute_confidence_intervals=compute_confidence_intervals,
              random_seed_for_testing=random_seed_for_testing,
          )
      )
  
      if min_slice_size > 1:
          metrics = (
              metrics
              | "FilterMetricsForSmallSlices"
              >> slicer.FilterOutSlices(
                  slices_count, min_slice_size, metric_keys.ERROR_METRIC
              )
          )
          plots = (
              plots
              | "FilterPlotsForSmallSlices"
              >> slicer.FilterOutSlices(
                  slices_count, min_slice_size, metric_keys.ERROR_METRIC
              )
          )
  
      if serialize:
          metrics = (
              metrics
              | "ConvertSliceMetricsToProto"
              >> beam.Map(
                  metrics_plots_and_validations_writer.convert_slice_metrics_to_proto,
                  add_metrics_callbacks=eval_shared_model.add_metrics_callbacks,
              )
              | "SerializeMetrics"
              >> beam.Map(lambda m: m.SerializeToString())
          )
          plots = (
              plots
              | "ConvertSlicePlotsToProto"
              >> beam.Map(
                  metrics_plots_and_validations_writer.convert_slice_plots_to_proto,
                  add_metrics_callbacks=eval_shared_model.add_metrics_callbacks,
              )
              | "SerializePlots"
              >> beam.Map(lambda p: p.SerializeToString())
          )
  
      return {metrics_key: metrics, plots_key: plots}
  
file_path: model-analysis/tensorflow_model_analysis/evaluators/legacy_metrics_and_plots_evaluator.py
imports: from typing import Any, Dict, Optional, Tuple
  import apache_beam
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.evaluators import counter_util
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators import legacy_aggregate
  from tensorflow_model_analysis.evaluators import legacy_poisson_bootstrap
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.extractors import slice_key_extractor
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.writers import metrics_plots_and_validations_writer
label_desc: Use image node_id 3 for calling a global function with example usage: _EvaluateMetricsAndPlots(extracts, eval_shared_model, desired_batch_size, metrics_key, plots_key, compute_confidence_intervals, min_slice_size, serialize, random_seed_for_testing) and returns: dict