original_docstring: Computes studentized residuals.
  
      Studentized residuals are just a deleted residual divided by its estimated
      standard deviation. This turns out to be equivalent to the ordinary residual
      divided by a factor that includes the mean square error based on the 
      estimated model with the ith observation deleted, MSE(i), and the leverage, hii
      .. math:: r_i = \\frac{e_i}{\\sqrt{MSE_{(i)}(1-h_{ii})}}
  
      Parameters
      ----------
      model : Estimator or BaseEstimator
          ML Studio or Scikit Learn estimator
  
      X : ndarray or DataFrame of shape n x m
          A matrix of n instances with m features
  
      y : ndarray or Series of length n
          An array or series of target or class values 
      
docstring: Computes studentized residuals.
  Studentized residuals are just a deleted residual divided by its estimated
  standard deviation. This turns out to be equivalent to the ordinary residual
  divided by a factor that includes the mean square error based on the
  estimated model with the ith observation deleted, MSE(i), and the leverage, hii
  math:: r_i = \\frac{e_i}{\\sqrt{MSE_{(i)}(1-h_{ii})}}
  
  Parameters
  
  model : Estimator or BaseEstimator
  ML Studio or Scikit Learn estimator
  
  X : ndarray or DataFrame of shape n x m
  A matrix of n instances with m features
  
  y : ndarray or Series of length n
  An array or series of target or class values
docstring_tokens: Computes studentized residuals . Studentized residuals are just a deleted residual divided by its estimated standard deviation . This turns out to be equivalent to the ordinary residual divided by a factor that includes the mean square error based on the estimated model with the ith observation deleted MSE ( i ) and the leverage hii math :: r_i = \\ frac { e_i } { \\ sqrt { MSE_ { ( i ) } ( 1 - h_ { ii } ) }} Parameters model : Estimator or BaseEstimator ML Studio or Scikit Learn estimator X : ndarray or DataFrame of shape n x m A matrix of n instances with m features y : ndarray or Series of length n An array or series of target or class values
code: def studentized_residuals(model, X, y, return_predictions=False):
      """Computes studentized residuals.
  
      Studentized residuals are just a deleted residual divided by its estimated
      standard deviation. This turns out to be equivalent to the ordinary residual
      divided by a factor that includes the mean square error based on the 
      estimated model with the ith observation deleted, MSE(i), and the leverage, hii
      .. math:: r_i = \\frac{e_i}{\\sqrt{MSE_{(i)}(1-h_{ii})}}
  
      Parameters
      ----------
      model : Estimator or BaseEstimator
          ML Studio or Scikit Learn estimator
  
      X : ndarray or DataFrame of shape n x m
          A matrix of n instances with m features
  
      y : ndarray or Series of length n
          An array or series of target or class values 
      """
      # Compute residuals
      y_pred = model.predict(X)
      
      # Using the calculation from 
      # https://newonlinecourses.science.psu.edu/stat462/node/247/
      n = X.shape[0]
      k = X.shape[1]
      r = standardized_residuals(model=model, X=X, y=y)
  
      # Calculate studentized residuals 
      studentized_residuals = r * np.sqrt((n-k-2)/(n-k-1-np.square(r)))
  
      # Return studentized residuals and optionally the predictions
      if return_predictions:
          return studentized_residuals, y_pred
      else:
          return studentized_residuals
code_tokens: def studentized_residuals ( model , X , y , return_predictions = False ) : y_pred = model . predict ( X ) n = X . shape [ 0 ] k = X . shape [ 1 ] r = standardized_residuals ( model = model , X = X , y = y ) studentized_residuals = r * np . sqrt ( ( n - k - 2 ) / ( n - k - 1 - np . square ( r ) ) ) if return_predictions : return studentized_residuals , y_pred else : return studentized_residuals
short_docstring: Computes studentized residuals.
short_docstring_tokens: Computes studentized residuals .
comment: """Computes studentized residuals.
  
      Studentized residuals are just a deleted residual divided by its estimated
      standard deviation. This turns out to be equivalent to the ordinary residual
      divided by a factor that includes the mean square error based on the 
      estimated model with the ith observation deleted, MSE(i), and the leverage, hii
      .. math:: r_i = \\frac{e_i}{\\sqrt{MSE_{(i)}(1-h_{ii})}}
  
      Parameters
      ----------
      model : Estimator or BaseEstimator
          ML Studio or Scikit Learn estimator
  
      X : ndarray or DataFrame of shape n x m
          A matrix of n instances with m features
  
      y : ndarray or Series of length n
          An array or series of target or class values 
      """$SEP$# Compute residuals$SEP$# Using the calculation from $SEP$# https://newonlinecourses.science.psu.edu/stat462/node/247/$SEP$# Calculate studentized residuals $SEP$# Return studentized residuals and optionally the predictions