code: def _mean_frequency_by_risk_group(
      y_true, y_pred, sample_weight=None, n_bins=100
  ):
      """Compare predictions and observations for bins ordered by y_pred.
  
      We order the samples by ``y_pred`` and split it in bins.
      In each bin the observed mean is compared with the predicted mean.
  
      Parameters
      ----------
      y_true: array-like of shape (n_samples,)
          Ground truth (correct) target values.
      y_pred: array-like of shape (n_samples,)
          Estimated target values.
      sample_weight : array-like of shape (n_samples,)
          Sample weights.
      n_bins: int
          Number of bins to use.
  
      Returns
      -------
      bin_centers: ndarray of shape (n_bins,)
          bin centers
      y_true_bin: ndarray of shape (n_bins,)
          average y_pred for each bin
      y_pred_bin: ndarray of shape (n_bins,)
          average y_pred for each bin
      """
      idx_sort = np.argsort(y_pred)
      bin_centers = np.arange(0, 1, 1 / n_bins) + 0.5 / n_bins
      y_pred_bin = np.zeros(n_bins)
      y_true_bin = np.zeros(n_bins)
  
      for n, sl in enumerate(gen_even_slices(len(y_true), n_bins)):
          weights = sample_weight[idx_sort][sl]
          y_pred_bin[n] = np.average(
              y_pred[idx_sort][sl], weights=weights
          )
          y_true_bin[n] = np.average(
              y_true[idx_sort][sl], weights=weights
          )
      return bin_centers, y_true_bin, y_pred_bin
  
file_path: scikit-learn/examples/linear_model/plot_poisson_regression_non_normal_loss.py
imports: import matplotlib.pyplot
  import numpy
  import pandas
  from sklearn.datasets import fetch_openml
  from sklearn.compose import ColumnTransformer
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import FunctionTransformer, KBinsDiscretizer, OneHotEncoder, StandardScaler
  from sklearn.dummy import DummyRegressor
  from sklearn.model_selection import train_test_split
  from sklearn.pipeline import Pipeline
  from sklearn.metrics import mean_absolute_error, mean_poisson_deviance, mean_squared_error
  from sklearn.linear_model import Ridge
  from sklearn.linear_model import PoissonRegressor
  from sklearn.ensemble import HistGradientBoostingRegressor
  from sklearn.preprocessing import OrdinalEncoder
  from sklearn.utils import gen_even_slices
  from sklearn.metrics import auc
label_desc: Use image node_id 2 for calling a global function with example usage: _mean_frequency_by_risk_group(y_true, y_pred, sample_weight, n_bins) and returns: bin_centers,  y_true_bin,  y_pred_bin