code: def calc_pred_coverage(observed, predicted, lower, upper, coverage):
      """Calculates the prediction coverages:
      prediction band width, prediction band coverage etc.
  
      :param observed: pd.Series or np.array, numeric, observed values
      :param predicted: pd.Series or np.array, numeric, predicted values
      :param lower: pd.Series or np.array, numeric, lower bound
      :param upper: pd.Series or np.array, numeric, upper bound
      :param coverage: float, intended coverage of the prediction bands (0.0 to 1.0)
      :return: prediction band width, prediction band coverage etc.
      """
      observed, predicted, lower, upper = valid_elements_for_evaluation(
          reference_arrays=[observed],
          arrays=[predicted, lower, upper],
          reference_array_names="y_true",
          drop_leading_only=False,
          keep_inf=False,
      )
      predicted, lower, upper, observed = valid_elements_for_evaluation(
          reference_arrays=[predicted, lower, upper],
          arrays=[observed],
          reference_array_names="y_pred and lower/upper bounds",
          drop_leading_only=True,
          keep_inf=True,
      )
      metrics = {}
  
      if len(observed) > 0:
          # Relative size of prediction bands vs actual, as a percent.
          enum = ValidationMetricEnum.BAND_WIDTH
          metric_func = enum.get_metric_func()
          metrics.update(
              {
                  PREDICTION_BAND_WIDTH: metric_func(
                      observed, lower, upper
                  )
              }
          )
  
          enum = ValidationMetricEnum.BAND_COVERAGE
          metric_func = enum.get_metric_func()
          # Fraction of observations within the bands.
          metrics.update(
              {
                  PREDICTION_BAND_COVERAGE: metric_func(
                      observed, lower, upper
                  )
              }
          )
          # Fraction of observations within the lower band.
          metrics.update(
              {
                  LOWER_BAND_COVERAGE: metric_func(
                      observed, lower, predicted
                  )
              }
          )
          # Fraction of observations within the upper band.
          metrics.update(
              {
                  UPPER_BAND_COVERAGE: metric_func(
                      observed, predicted, upper
                  )
              }
          )
          # Difference between actual and intended coverage.
          metrics.update(
              {
                  COVERAGE_VS_INTENDED_DIFF: (
                      metrics[PREDICTION_BAND_COVERAGE] - coverage
                  )
              }
          )
  
          # Mean interval score.
          enum = ValidationMetricEnum.MEAN_INTERVAL_SCORE
          metric_func = enum.get_metric_func()
          metric_name = enum.get_metric_name()
          metrics.update(
              {
                  metric_name: (
                      metric_func(observed, lower, upper, coverage)
                  )
              }
          )
      return metrics
  
imports: import math
  import warnings
  from collections import namedtuple
  from enum import Enum
  from functools import partial
  from typing import List
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from scipy.stats import pearsonr
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import median_absolute_error
  from sklearn.metrics import r2_score
  from greykite.common.constants import ACTUAL_COL
  from greykite.common.constants import COVERAGE_VS_INTENDED_DIFF
  from greykite.common.constants import LOWER_BAND_COVERAGE
  from greykite.common.constants import PREDICTED_COL
  from greykite.common.constants import PREDICTED_LOWER_COL
  from greykite.common.constants import PREDICTED_UPPER_COL
  from greykite.common.constants import PREDICTION_BAND_COVERAGE
  from greykite.common.constants import PREDICTION_BAND_WIDTH
  from greykite.common.constants import UPPER_BAND_COVERAGE
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
label_desc: Use image node_id 19 for calling a global function with example usage: calc_pred_coverage(observed, predicted, lower, upper, coverage) and returns: metrics