code: def _Cooks_dist(X, y, model):
      """Calculated the Cook's distance
  
      Parameters
      ----------
      X : numpy array of shape (n_samples, n_features)
          The training dataset.
  
      y : numpy array of shape (n_samples)
          The training datset
  
      model : object
          Regression model used to calculate the Cook's distance
  
      Returns
      -------
      distances_ : numpy array of shape (n_samples)
          Cook's distance
      """
  
      # Leverage is computed as the diagonal of the projection matrix of X
      leverage = (X * np.linalg.pinv(X).T).sum(1)
  
      # Compute the rank and the degrees of freedom of the model
      rank = np.linalg.matrix_rank(X)
      df = X.shape[0] - rank
  
      # Compute the MSE from the residuals
      residuals = y - model.predict(X)
      mse = np.dot(residuals, residuals) / df
  
      # Compute Cook's distance
      if (mse != 0) or (mse != np.nan):
          residuals_studentized = (
              residuals / np.sqrt(mse) / np.sqrt(1 - leverage)
          )
          distance_ = residuals_studentized**2 / X.shape[1]
          distance_ *= leverage / (1 - leverage)
          distance_ = (distance_ - distance_.min()) / (
              distance_.max() - distance_.min()
          )
  
      else:
          distance_ = np.ones(len(y)) * np.nan
  
      return distance_
  
file_path: pyod/pyod/models/cd.py
imports: from __future__ import division
  from __future__ import print_function
  import numpy
  from sklearn.linear_model import LinearRegression
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from .base import BaseDetector
label_desc: Use image node_id 1 for calling a global function with example usage: _Cooks_dist(X, y, model) and returns: distance_