code: def cooks_distance(
      standardized_residuals: np.ndarray,
      leverage_statistic: np.ndarray,
      n_model_params: int = None,
  ) -> np.array:
      """
      The Cook’s distance $d_i$ measures to which extent the predicted value $\hat y_i$ changes if the ith observation
      is removed. It can be efficiently calculated using the leverage statistics $h_i$, the standardized
      residuals $\tilde r_i$ and the number of predictor variables $p$.
      $d_{i}=\frac{h_{i}}{1-h_{i}} \frac{\widetilde{r}_{i}^{2}}{p+1}$
      The larger the value of Cook’s distance $d_i$ is, the higher is the influence of the corresponding observation on
      the estimation of the predicted value $\hat y_i$. In practice, we consider a value of Cook’s distance larger than 1
      as dangerously influential.
  
      Parameters
      ----------
      standardized_residuals: np.array
          the standardized residuals for the predictions of some model w.r.t a specific dataset $X$
  
      leverage_statistic: np.array
          the leverage statistics for the same dataset $X$ used to calculate the standardized residuals
  
      n_model_params: int, Optional
          the number of parameters contained in the analysed model, used as a indicator for the number of predictor
          variables $p$. If None, a linear model is assumed which has $p=1$.
  
  
      Returns
      -------
          np.array: A array containing the Cook's distance for each observation $x_i$ in the dataset $X$
  
      """
      p = (
          n_model_params
          if n_model_params is not None and n_model_params >= 1
          else 1
      )
      multiplier = [
          element / (1 - element) for element in leverage_statistic
      ]
      distance = np.multiply(
          np.power(standardized_residuals, 2) / (p + 1), multiplier
      )
      return distance
  
file_path: pycaret/pycaret/internal/plots/helper.py
imports: import numpy
  import scikitplot
label_desc: Use image node_id 3 for calling a global function with example usage: cooks_distance(standardized_residuals, leverage_statistic, n_model_params) and returns: distance