code: def prediction_error(y_true, y_pred, ax=None):
      """
      Plot the scatter plot of measured values v. predicted values, with
      an identity line and a best fitted line to show the prediction
      difference.
  
      Parameters
      ----------
      y_true : array-like, shape = [n_samples]
          Measured target values (ground truth).
      y_pred : array-like, shape = [n_samples]
          Predicted target values.
      ax : matplotlib Axes
          Axes object to draw the plot onto, otherwise uses current Axes
  
      Returns
      -------
      ax: matplotlib Axes
          Axes containing the plot
  
      Examples
      --------
      .. plot:: ../examples/prediction_error.py
  
      """
      _check_parameter_validity(y_true, y_pred)
      if ax is None:
          ax = plt.gca()
  
      model = LinearRegression()
  
      if isinstance(y_true, pd.Series):
          y_true = y_true.values
      y_reshaped = y_true.reshape((-1, 1))
  
      # it is necessary to fit the model with y_true and y_pred
      # to get the best fit line representing the error trend
      model.fit(y_reshaped, y_pred)
      x = np.linspace(
          min(min(y_true), min(y_pred)), max(max(y_true), max(y_pred))
      )
      y = model.intercept_ + model.coef_ * x
      ax.plot(x, y, "-b", label="best fit")
  
      # identity line
      ax.plot(x, x, "--k", label="identity")
  
      # scatter plot
      ax.scatter(y_true, y_pred)
  
      # R2
      r2 = model.score(y_reshaped, y_pred)
      plt.plot([], [], " ", label=f"R2 = {round(r2,5)}")
  
      _set_ax_settings(ax, "y_true", "y_pred", "Prediction Error")
      ax.legend(loc="upper left")
      return ax
  
file_path: sklearn-evaluation/src/sklearn_evaluation/plot/regression.py
imports: import matplotlib.pyplot
  import numpy
  import pandas
  from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
  from sklearn.linear_model import LinearRegression
  from ploomber_core.exceptions import modify_exceptions
label_desc: Use image node_id 4 for calling a global function with example usage: prediction_error(y_true, y_pred, ax) and returns: ax