code: def calculate_standardized_residual(
      predicted: np.ndarray,
      expected: np.ndarray = None,
      featuresize: int = None,
  ) -> np.ndarray:
      """
      Calculates the standardized residuals $\tilde r_i$ of the predictions to the expectations.
      $\tilde{r}_{i}=\frac{r_{i}}{\widehat{\sigma} \sqrt{1-\left(\frac{1}{n}+\frac{\left(y_{i}-\bar{y}\right)^{2}}{\sum_{i}^{n}\left(y_{i}-\bar{y}\right)^{2}}\right)}}$
      where $r_i= y_i - \hat y_i$ and $\hat \sigma$ denote the estimated standard deviation of the error terms $\epsilon_i\approx r_i$.
      If the error terms $\epsilon_i$ are distributed according to a normal distribution, then for the distribution of the
      standardized residuals, we have $\tilde r_i \sim \mathcal N(0,1)$.
  
      Parameters
      ----------
      predicted: np.array
          the predicted values (y_pred)
      expected: np.array
          the expected values for the predictions (y_true)
      featuresize: int
          Optional, number of features per observation, If it is None, a featuresize of 1 is assumed
  
      Returns
      -------
          np.array: An array containing the standardized residuals of the predictions
  
      """
      if expected is not None:
          residuals = expected - predicted
      else:
          residuals = predicted
          expected = predicted
  
      if residuals.sum() == 0:
          return residuals
  
      n = residuals.shape[0]
      m = featuresize
      if m is None:
          m = 1
      s2_hat = 1 / (n - m) * np.sum(residuals**2)
      leverage = 1 / n + (expected - np.mean(expected)) / np.sum(
          (expected - np.mean(expected)) ** 2
      )
      standardized_residuals = residuals / (
          np.sqrt(s2_hat) * (1 - leverage)
      )
      return standardized_residuals
  
file_path: pycaret/pycaret/internal/plots/helper.py
imports: import numpy
  import scikitplot
label_desc: Use image node_id 2 for calling a global function with example usage: calculate_standardized_residual(predicted, expected, featuresize) and returns: standardized_residuals, residuals