class_docstr: This widget compares the standardized residuals $   ilde r_i$ versus the leverage $h_i$ of the corresponding observation $x_i$.
  Assuming that $Y=f(X)+\epsilon$ we can verify with this plot that the error terms $\epsilon_i$ are independent.
  The cook's distance is a measure to which extent some points are high leverage points and/or outliers.
  Cook's distance (function of leverage and residual) is a measure of how influential a data point is.
  If a point lies beyond of contour lines corresponding to a Cook's distance larger than 1, then this point should be
  considered as dangerously influential.
class_docstr_tok: ["This","widget","compares","the","standardized","residuals","$","ilde","r_i","$","versus","the","leverage","$","h_i","$","of","the","corresponding","observation","$","x_i","$",".","Assuming","that","$","Y=f","(","X",")","+\\epsilon","$","we","can","verify","with","this","plot","that","the","error","terms","$","\\epsilon_i","$","are","independent",".","The","cook","'s","distance","is","a","measure","to","which","extent","some","points","are","high","leverage","points","and\/or","outliers",".","Cook","'s","distance","(","function","of","leverage","and","residual",")","is","a","measure","of","how","influential","a","data","point","is",".","If","a","point","lies","beyond","of","contour","lines","corresponding","to","a","Cook","'s","distance","larger","than","1",",","then","this","point","should","be","considered","as","dangerously","influential","."]
code: def __cooks_distance_plot(
      model_leverage,
      cooks_distances,
      standardized_residuals,
      n_model_params,
      split_origin,
  ):
      cooks_distances = pd.Series(cooks_distances)
  
      if split_origin is not None:
          dataframe = pd.DataFrame(
              {
                  "Leverage": model_leverage,
                  "Standardized Residuals": standardized_residuals,
                  "Split": split_origin,
              }
          )
          fig = px.scatter(
              dataframe,
              x="Leverage",
              y="Standardized Residuals",
              trendline="lowess",
              color="Split",
              color_discrete_sequence=["blue", "green"],
              title="Residuals vs Leverage",
              opacity=0.3,
          )
  
          fig.update_layout(showlegend=False)
      else:
          dataframe = pd.DataFrame(
              {
                  "Leverage": model_leverage,
                  "Standardized Residuals": standardized_residuals,
              }
          )
          fig = px.scatter(
              dataframe,
              x="Leverage",
              y="Standardized Residuals",
              trendline="lowess",
              title="Residuals vs Leverage",
              opacity=0.3,
          )
  
      maxmo = max(model_leverage) * 1.05
      fig.update_xaxes(range=[0, maxmo])
      min_r = min(standardized_residuals)
      max_r = max(standardized_residuals)
      fig.update_yaxes(
          range=[min_r - 0.05 * abs(min_r), max_r + 0.05 * abs(max_r)]
      )
      leverage_top_3 = cooks_distances.sort_values(ascending=False)[:3]
      for i in leverage_top_3.index:
          fig.add_annotation(
              x=model_leverage[i],
              y=standardized_residuals[i],
              text=f"~r_{i}",
          )
  
      fig.update_annotations(
          dict(
              xref="x",
              yref="y",
              showarrow=True,
              arrowhead=7,
              ax=0,
              ay=-40,
          )
      )
  
      def graph(formula, x_range, label, c, text):
          x = x_range
          y = formula(x)
  
          text_list = ["" for _ in range(x_range.shape[0])]
          text_list[x_range.shape[0] // 4] = text
          text_list[(x_range.shape[0] // 4) * 3] = text
  
          fig.add_trace(
              go.Scatter(
                  x=x,
                  y=y,
                  name=label,
                  line=dict(color=c, width=2, dash="dash"),
                  mode="lines+text",
                  textposition="bottom center",
                  showlegend=False,
                  text=text_list,
              )
          )
  
          fig.add_trace(
              go.Scatter(
                  x=x,
                  y=-y,
                  name=label,
                  line=dict(color=c, width=2, dash="dash"),
                  mode="lines+text",
                  textposition="top center",
                  showlegend=False,
                  text=text_list,
              )
          )
  
      p = n_model_params
      graph(
          lambda x: np.sqrt(np.abs((0.5 * (p + 1) * (1 - x)) / x)),
          np.linspace(0.001, max(model_leverage), 50),
          "Cook's distance = 0.5",
          "coral",
          "0.5",
      )
  
      graph(
          lambda x: np.sqrt(np.abs((1 * (p + 1) * (1 - x)) / x)),
          np.linspace(0.001, max(model_leverage), 50),
          "Cook's distance = 1",
          "firebrick",
          "1",
      )
      return fig
  
imports: from typing import List, Optional
  import numpy
  import pandas
  import plotly.express
  import plotly.graph_objects
  from ipywidgets import Layout, widgets
  from plotly.basewidget import BaseFigureWidget
  from scipy import stats
  import pycaret.internal.plots.helper
  from pycaret.internal.display import CommonDisplay
  from pycaret.internal.display.display_backend import ColabBackend, DatabricksBackend
  from pycaret.internal.logging import get_logger
  from pycaret.internal.validation import fit_if_not_fitted
label_desc: Use image node_id 2 for calling the CooksDistanceWidget obj's underlying member method code with example usage: obj.__cooks_distance_plot(model_leverage, cooks_distances, standardized_residuals, n_model_params, split_origin) and returns: fig