code: def _calibration_plot(
      num_buckets: int = DEFAULT_NUM_BUCKETS,
      left: Optional[float] = None,
      right: Optional[float] = None,
      name: str = CALIBRATION_PLOT_NAME,
      eval_config: Optional[config_pb2.EvalConfig] = None,
      schema: Optional[schema_pb2.Schema] = None,
      model_name: str = "",
      output_name: str = "",
      sub_key: Optional[metric_types.SubKey] = None,
      aggregation_type: Optional[metric_types.AggregationType] = None,
      class_weights: Optional[Dict[int, float]] = None,
      example_weighted: bool = False,
  ) -> metric_types.MetricComputations:
      """Returns metric computations for calibration plot."""
      key = metric_types.PlotKey(
          name=name,
          model_name=model_name,
          output_name=output_name,
          sub_key=sub_key,
          example_weighted=example_weighted,
      )
  
      label_left, label_right = None, None
      if (left is None or right is None) and eval_config and schema:
          label_left, label_right = _find_label_domain(
              eval_config, schema, model_name, output_name
          )
      if left is None:
          left = label_left if label_left is not None else 0.0
      if right is None:
          right = label_right if label_right is not None else 1.0
  
      # Make sure calibration histogram is calculated. Note we are using the default
      # number of buckets assigned to the histogram instead of the value used for
      # the plots just in case the computation is shared with other metrics and
      # plots that need higher preicion. It will be downsampled later.
      computations = calibration_histogram.calibration_histogram(
          eval_config=eval_config,
          model_name=model_name,
          output_name=output_name,
          sub_key=sub_key,
          left=left,
          right=right,
          aggregation_type=aggregation_type,
          class_weights=class_weights,
          example_weighted=example_weighted,
      )
      histogram_key = computations[-1].keys[-1]
  
      def result(
          metrics: Dict[metric_types.MetricKey, Any]
      ) -> Dict[metric_types.MetricKey, Any]:
          thresholds = [
              left + i * (right - left) / num_buckets
              for i in range(num_buckets + 1)
          ]
          thresholds = [float("-inf")] + thresholds
          histogram = calibration_histogram.rebin(
              thresholds, metrics[histogram_key], left=left, right=right
          )
          return {key: _to_proto(thresholds, histogram)}
  
      derived_computation = metric_types.DerivedMetricComputation(
          keys=[key], result=result
      )
      computations.append(derived_computation)
      return computations
  
file_path: model-analysis/tensorflow_model_analysis/metrics/calibration_plot.py
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  from tensorflow_model_analysis.metrics import calibration_histogram
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: _calibration_plot(num_buckets, left, right, name, eval_config, schema, model_name, output_name, sub_key, aggregation_type, class_weights, example_weighted) and returns: computations, dict