code: def leverage_statistic(x: np.ndarray):
      """
      Calculates the leverage statistic $h_i$ for all $n$ observations $x_i$ within $X$.
      $h=\text{diag} \left(X\left(X^{\top} X\right)^{-1} X^{\top}\right)$
      Observations with high leverage have an unusual value for $x_i$.
  
      Parameters
      ----------
      X: np.array
          A collection of observations $x_i$, where $dim(X)=2$. The first dimension describes the number of observations $n$
          and the second the number of features.
  
      Returns
      -------
          np.array: An array containing the leverage of each observation $x_i$, hence it has length $n$.
  
      """
      if x.ndim == 1:
          x = x.reshape(x.shape[0], 1)
  
      cov_mat_inv = np.linalg.inv(x.T.dot(x))
      H = x.dot(cov_mat_inv.dot(x.T))
      leverage = H.diagonal()
      return leverage
  
file_path: pycaret/pycaret/internal/plots/helper.py
imports: import numpy
  import scikitplot
label_desc: Use image node_id 1 for calling a global function with example usage: leverage_statistic(x) and returns: leverage