code: def expected_calibration_error(
      prediction_probabilities, accuracy, confidence
  ):
      """
      Helper function for calculating the expected calibration error as defined in
      the paper On Calibration of Modern Neural Networks, C. Guo, et. al., ICML, 2017
  
      It is assumed that for a validation dataset, the prediction probabilities have
      been calculated for each point in the dataset and given in the array
      prediction_probabilities.
  
      .. seealso::
  
         `Examples using calibration <https://stellargraph.readthedocs.io/en/stable/demos/calibration/index.html>`__.
  
         Related functionality: :func:`.plot_reliability_diagram`, :class:`.IsotonicCalibration`, :class:`.TemperatureCalibration`.
  
      Args:
          prediction_probabilities (numpy array):  The predicted probabilities.
          accuracy (numpy array): The accuracy such that the i-th entry in the array holds the proportion of correctly
              classified samples that fall in the i-th bin.
          confidence (numpy array): The confidence such that the i-th entry in the array is the average prediction
              probability over all the samples assigned to this bin.
  
      Returns:
          float: The expected calibration error.
  
      """
      if not isinstance(prediction_probabilities, np.ndarray):
          raise ValueError(
              "Parameter prediction_probabilities must be type numpy.ndarray but given object of type {}".format(
                  type(prediction_probabilities).__name__
              )
          )
      if not isinstance(accuracy, np.ndarray):
          raise ValueError(
              "Parameter accuracy must be type numpy.ndarray but given object of type {}".format(
                  type(accuracy).__name__
              )
          )
      if not isinstance(confidence, np.ndarray):
          raise ValueError(
              "Parameter confidence must be type numpy.ndarray but given object of type {}".format(
                  type(confidence).__name__
              )
          )
  
      if len(accuracy) != len(confidence):
          raise ValueError(
              "Arrays accuracy and confidence should have the same size but instead received {} and {} respectively.".format(
                  len(accuracy), len(confidence)
              )
          )
  
      n_bins = len(accuracy)  # the number of bins
      n = len(prediction_probabilities)  # number of samples
      h = np.histogram(
          a=prediction_probabilities, range=(0, 1), bins=n_bins
      )[
          0
      ]  # just the counts
      ece = 0
      for m in np.arange(n_bins):
          ece = ece + (h[m] / n) * np.abs(accuracy[m] - confidence[m])
      return ece
  
imports: import numpy
  import matplotlib.pyplot
  import tensorflow
  from sklearn.isotonic import IsotonicRegression
  from sklearn.linear_model import LogisticRegression
label_desc: Use image node_id 1 for calling a global function with example usage: expected_calibration_error(prediction_probabilities, accuracy, confidence) and returns: ece