code: def cooks_distance(
      X,
      y,
      ax=None,
      draw_threshold=True,
      linefmt="C0-",
      markerfmt=",",
      show=True,
      **kwargs,
  ):
      """
      Cook's Distance is a measure of how influential an instance is to the computation of
      a regression, e.g. if the instance is removed would the estimated coeficients of the
      underlying model be substantially changed? Because of this, Cook's Distance is
      generally used to detect outliers in standard, OLS regression. In fact, a general
      rule of thumb is that D(i) > 4/n is a good threshold for determining highly
      influential points as outliers and this visualizer can report the percentage of data
      that is above that threshold.
  
      This implementation of Cook's Distance assumes Ordinary Least Squares regression,
      and therefore embeds a ``sklearn.linear_model.LinearRegression`` under the hood.
      Distance is computed via the non-whitened leverage of the projection matrix,
      computed inside of ``fit()``. The results of this visualizer are therefore similar
      to, but not as advanced, as a similar computation using statsmodels. Computing the
      influence for other regression models requires leave one out validation and can be
      expensive to compute.
  
      .. seealso::
          For a longer discussion on detecting outliers in regression and computing
          leverage and influence, see `linear regression in python, outliers/leverage
          detect <http://bit.ly/2If2fga>`_ by Huiming Song.
  
      Parameters
      ----------
      X : array-like, 2D
          The exogenous design matrix, e.g. training data.
  
      y : array-like, 1D
          The endogenous response variable, e.g. target data.
  
      ax : matplotlib Axes, default: None
          The axes to plot the figure on. If None is passed in the current axes
          will be used (or generated if required).
  
      draw_threshold : bool, default: True
          Draw a horizontal line at D(i) == 4/n to easily identify the most influential
          points on the final regression. This will also draw a legend that specifies the
          percentage of data points that are above the threshold.
  
      linefmt : str, default: 'C0-'
          A string defining the properties of the vertical lines of the stem plot, usually
          this will be a color or a color and a line style. The default is simply a solid
          line with the first color of the color cycle.
  
      markerfmt: str, default: ','
          A string defining the properties of the markers at the stem plot heads. The
          default is "pixel", e.g. basically no marker head at the top of the stem plot.
  
      show: bool, default: True
          If True, calls ``show()``, which in turn calls ``plt.show()`` however
          you cannot call ``plt.savefig`` from this signature, nor
          ``clear_figure``. If False, simply calls ``finalize()``
  
      kwargs : dict
          Keyword arguments that are passed to the base class and may influence the final
          visualization (e.g. size or title parameters).
      """
      viz = CooksDistance(
          ax=ax,
          draw_threshold=draw_threshold,
          linefmt=linefmt,
          markerfmt=markerfmt,
          **kwargs,
      )
      viz.fit(X, y)
  
      # Draw the final visualization
      if show:
          viz.show()
      else:
          viz.finalize()
  
      # Return the visualizer
      return viz
  
file_path: yellowbrick/yellowbrick/regressor/influence.py
imports: import numpy
  import scipy
  from yellowbrick.base import Visualizer
  from sklearn.linear_model import LinearRegression
label_desc: Use image node_id 1 for calling a global function with example usage: cooks_distance(X, y, ax, draw_threshold, linefmt, markerfmt, show) and returns: viz