original_docstring: 
          Performs a bootstrap for a given regression type, design matrix 
          function and excact function.
  
          Args:
              N_bs (int): number of bootstraps to perform
              test_percent (float): what percentage of data to reserve for 
                  testing. optional, default is 0.25.
              X_test (ndarray): design matrix for test values, shape (N, p), 
                  optional. Will use instead of splitting dataset by test 
                  percent.
              y_test (ndarray): y test data on shape (N, 1), optional. Will 
                  use instead of splitting dataset by test percent.
              shuffle (bool): if we are to shuffle the data when no test data 
                  is provided. Default is False.
          
docstring: Performs a bootstrap for a given regression type, design matrix
  function and excact function.
docstring_tokens: Performs a bootstrap for a given regression type design matrix function and excact function .
code: def bootstrap(self, N_bs, test_percent=0.25, X_test=None, y_test=None,
                    shuffle=False):
          """
          Performs a bootstrap for a given regression type, design matrix 
          function and excact function.
  
          Args:
              N_bs (int): number of bootstraps to perform
              test_percent (float): what percentage of data to reserve for 
                  testing. optional, default is 0.25.
              X_test (ndarray): design matrix for test values, shape (N, p), 
                  optional. Will use instead of splitting dataset by test 
                  percent.
              y_test (ndarray): y test data on shape (N, 1), optional. Will 
                  use instead of splitting dataset by test percent.
              shuffle (bool): if we are to shuffle the data when no test data 
                  is provided. Default is False.
          """
  
          assert not isinstance(self._reg, type(None))
  
          assert test_percent < 1.0, "test_percent must be less than one."
  
          N = len(self.X_data)
  
          X = self.X_data
          y = self.y_data
  
          # Checks if we have provided test data or not
          if isinstance(X_test, type(None)) and \
                  isinstance(y_test, type(None)):
  
              # Splits X data and design matrix data
              X_train, X_test, y_train, y_test = \
                  sk_modsel.train_test_split(self.X_data, self.y_data,
                                             test_size=test_percent,
                                             shuffle=False)
          else:
              # If X_test and y_test is provided, we simply use those as test
              # values.
              X_train = self.X_data
              y_train = self.y_data
  
          self.x_pred_test = X_test[:, 1]
  
          # Sets up emtpy lists for gathering the relevant scores in
          r2_list = np.empty(N_bs)
          beta_coefs = []
  
          y_pred_list = np.empty((X_test.shape[0], N_bs))
  
          # # Sets up jobs for parallel processing
          # input_values = list(zip([X_train for i in range(N_bs)],
          #                    [y_train for i in range(N_bs)],
          #                    [X_test for i in range(N_bs)],
          #                    [y_test for i in range(N_bs)],
          #                    [cp.deepcopy(self.reg) for i in range(N_bs)]))
          # print (input_values[0])
          # # Initializes multiprocessing
          # pool = multiprocessing.Pool(processes=4)
  
          # # Runs parallel processes. Can this be done more efficiently?
          # results = pool.map(_para_bs, input_values)
          # print (results)
          # # [sk_metrics.r2_score(y_test, y_predict),
          # #     y_predict.ravel(),
          # #     reg.coef_]
  
          # # Garbage collection for multiprocessing instance
          # pool.close()
  
          # Bootstraps
          for i_bs in tqdm(range(N_bs), desc="Bootstrapping"):
              # Bootstraps test data
              # x_boot, y_boot = boot(x_train, y_train)
  
              X_boot, y_boot = boot(X_train, y_train)
              # X_boot, y_boot = sk_utils.resample(X_train, y_train)
              # Sets up design matrix
              # X_boot = self._design_matrix(x_boot)
  
              # Fits the bootstrapped values
              self.reg.fit(X_boot, y_boot)
  
              # Tries to predict the y_test values the bootstrapped model
              y_predict = self.reg.predict(X_test)
  
              # Calculates r2
              # r2_list[i_bs] = metrics.r2(y_test, y_predict)
              r2_list[i_bs] = sk_metrics.r2_score(y_test, y_predict)
  
              # mse_list[i_bs] = metrics.mse(y_predict, y_test)
              # bias_list[i_bs] = metrics.bias(y_predict, y_test)
              # var_list[i_bs] = np.var(y_predict)
  
              # Stores the prediction and beta coefs.
              y_pred_list[:, i_bs] = y_predict.ravel()
              beta_coefs.append(self.reg.coef_)
  
          # pred_list_bs = np.mean(y_pred_list, axis=0)
  
          # R^2 score, 1 - sum(y-y_approx)/sum(y-mean(y))
          self.r2 = np.mean(r2_list)
  
          # Mean Square Error, mean((y - y_approx)**2)
          # _mse = np.mean((y_test.ravel() - y_pred_list)**2,
          #                axis=0, keepdims=True)
  
          # _mse = np.mean((y_test - y_pred_list)**2,
          #                axis=1, keepdims=True)
          # self.mse = np.mean(_mse)
  
          # # Bias, (y - mean(y_approx))^2
          # _y_pred_mean = np.mean(y_pred_list, axis=1, keepdims=True)
          # self.bias = np.mean((y_test - _y_pred_mean)**2)
  
          # # Variance, var(y_approx)
          # self.var = np.mean(np.var(y_pred_list,
          #                           axis=1, keepdims=True))
  
          _y_pred_mean = np.mean(y_pred_list, axis=1, keepdims=True)
          self.bias = np.mean((y_test - _y_pred_mean)**2)
  
          # Variance, var(y_approx)
          self.var = np.mean(np.var(y_pred_list, axis=1, keepdims=True))
  
          self.mse = np.mean(
              np.mean((y_test - y_pred_list)**2, axis=1, keepdims=True))
          # self.bias = np.mean(
          #     y_test - np.mean(y_pred_list, axis=1, keepdims=True))**2
  
          beta_coefs = np.asarray(beta_coefs)
  
          self.beta_coefs_var = np.asarray(beta_coefs).var(axis=0)
          self.beta_coefs = np.asarray(beta_coefs).mean(axis=0)
  
          self.y_pred = y_pred_list.mean(axis=1)
          self.y_pred_var = y_pred_list.var(axis=1)
code_tokens: def bootstrap ( self , N_bs , test_percent = 0.25 , X_test = None , y_test = None , shuffle = False ) : assert not isinstance ( self . _reg , type ( None ) ) assert test_percent < 1.0 , "test_percent must be less than one." N = len ( self . X_data ) X = self . X_data y = self . y_data if isinstance ( X_test , type ( None ) ) and isinstance ( y_test , type ( None ) ) : X_train , X_test , y_train , y_test = sk_modsel . train_test_split ( self . X_data , self . y_data , test_size = test_percent , shuffle = False ) else : X_train = self . X_data y_train = self . y_data self . x_pred_test = X_test [ : , 1 ] r2_list = np . empty ( N_bs ) beta_coefs = [ ] y_pred_list = np . empty ( ( X_test . shape [ 0 ] , N_bs ) ) for i_bs in tqdm ( range ( N_bs ) , desc = "Bootstrapping" ) : X_boot , y_boot = boot ( X_train , y_train ) self . reg . fit ( X_boot , y_boot ) y_predict = self . reg . predict ( X_test ) r2_list [ i_bs ] = sk_metrics . r2_score ( y_test , y_predict ) y_pred_list [ : , i_bs ] = y_predict . ravel ( ) beta_coefs . append ( self . reg . coef_ ) self . r2 = np . mean ( r2_list ) _y_pred_mean = np . mean ( y_pred_list , axis = 1 , keepdims = True ) self . bias = np . mean ( ( y_test - _y_pred_mean ) ** 2 ) self . var = np . mean ( np . var ( y_pred_list , axis = 1 , keepdims = True ) ) self . mse = np . mean ( np . mean ( ( y_test - y_pred_list ) ** 2 , axis = 1 , keepdims = True ) ) beta_coefs = np . asarray ( beta_coefs ) self . beta_coefs_var = np . asarray ( beta_coefs ) . var ( axis = 0 ) self . beta_coefs = np . asarray ( beta_coefs ) . mean ( axis = 0 ) self . y_pred = y_pred_list . mean ( axis = 1 ) self . y_pred_var = y_pred_list . var ( axis = 1 )
short_docstring: Performs a bootstrap for a given regression type, design matrix
  function and excact function.
short_docstring_tokens: Performs a bootstrap for a given regression type design matrix function and excact function .
comment: """
          Performs a bootstrap for a given regression type, design matrix 
          function and excact function.
  
          Args:
              N_bs (int): number of bootstraps to perform
              test_percent (float): what percentage of data to reserve for 
                  testing. optional, default is 0.25.
              X_test (ndarray): design matrix for test values, shape (N, p), 
                  optional. Will use instead of splitting dataset by test 
                  percent.
              y_test (ndarray): y test data on shape (N, 1), optional. Will 
                  use instead of splitting dataset by test percent.
              shuffle (bool): if we are to shuffle the data when no test data 
                  is provided. Default is False.
          """$SEP$# Checks if we have provided test data or not$SEP$# Splits X data and design matrix data$SEP$# If X_test and y_test is provided, we simply use those as test$SEP$# values.$SEP$# Sets up emtpy lists for gathering the relevant scores in$SEP$# # Sets up jobs for parallel processing$SEP$# input_values = list(zip([X_train for i in range(N_bs)],$SEP$#                    [y_train for i in range(N_bs)],$SEP$#                    [X_test for i in range(N_bs)],$SEP$#                    [y_test for i in range(N_bs)],$SEP$#                    [cp.deepcopy(self.reg) for i in range(N_bs)]))$SEP$# print (input_values[0])$SEP$# # Initializes multiprocessing$SEP$# pool = multiprocessing.Pool(processes=4)$SEP$# # Runs parallel processes. Can this be done more efficiently?$SEP$# results = pool.map(_para_bs, input_values)$SEP$# print (results)$SEP$# # [sk_metrics.r2_score(y_test, y_predict),$SEP$# #     y_predict.ravel(),$SEP$# #     reg.coef_]$SEP$# # Garbage collection for multiprocessing instance$SEP$# pool.close()$SEP$# Bootstraps$SEP$# Bootstraps test data$SEP$# x_boot, y_boot = boot(x_train, y_train)$SEP$# X_boot, y_boot = sk_utils.resample(X_train, y_train)$SEP$# Sets up design matrix$SEP$# X_boot = self._design_matrix(x_boot)$SEP$# Fits the bootstrapped values$SEP$# Tries to predict the y_test values the bootstrapped model$SEP$# Calculates r2$SEP$# r2_list[i_bs] = metrics.r2(y_test, y_predict)$SEP$# mse_list[i_bs] = metrics.mse(y_predict, y_test)$SEP$# bias_list[i_bs] = metrics.bias(y_predict, y_test)$SEP$# var_list[i_bs] = np.var(y_predict)$SEP$# Stores the prediction and beta coefs.$SEP$# pred_list_bs = np.mean(y_pred_list, axis=0)$SEP$# R^2 score, 1 - sum(y-y_approx)/sum(y-mean(y))$SEP$# Mean Square Error, mean((y - y_approx)**2)$SEP$# _mse = np.mean((y_test.ravel() - y_pred_list)**2,$SEP$#                axis=0, keepdims=True)$SEP$# _mse = np.mean((y_test - y_pred_list)**2,$SEP$#                axis=1, keepdims=True)$SEP$# self.mse = np.mean(_mse)$SEP$# # Bias, (y - mean(y_approx))^2$SEP$# _y_pred_mean = np.mean(y_pred_list, axis=1, keepdims=True)$SEP$# self.bias = np.mean((y_test - _y_pred_mean)**2)$SEP$# # Variance, var(y_approx)$SEP$# self.var = np.mean(np.var(y_pred_list,$SEP$#                           axis=1, keepdims=True))$SEP$# Variance, var(y_approx)$SEP$# self.bias = np.mean($SEP$#     y_test - np.mean(y_pred_list, axis=1, keepdims=True))**2