code: def __calculate_y_hat(X_base, group2ids, testLabel, cov=covdf_empty):
      groups = sorted(group2ids.keys(), key=lambda v: v)
      cov_X = pd.concat([cov, X_base], axis=1, sort=True)
      headersToKeep = list(cov.columns) + [
          c for c in X_base.columns if testLabel in c
      ]
      n_cov = len(cov.columns)
  
      r2s = []
      for group in groups:
          ids = group2ids[group]
          X_in = cov_X[headersToKeep].loc[ids, :].to_numpy()
          X_out = cov_X[headersToKeep].drop(ids, axis="rows")
          Y_in = std_labeldf[testLabel].loc[ids].to_numpy()
          Y_out = std_labeldf[testLabel].loc[X_out.index].to_numpy()
          XtX_out = X_out.to_numpy().T @ X_out.to_numpy()
          XtY_out = X_out.to_numpy().T @ Y_out
          diags = [
              np.concatenate(
                  [
                      np.ones(n_cov),
                      np.ones(XtX_out.shape[1] - n_cov) * a,
                  ]
              )
              for a in alphas
          ]
          B = np.column_stack(
              [
                  (np.linalg.inv(XtX_out + np.diag(d)) @ XtY_out)
                  for d in diags
              ]
          )[:, coefOrder]
          XB = X_in @ B
          r2 = r_squared(XB, Y_in.reshape(-1, 1))
          r2s.append(r2)
      r2_mean = np.row_stack(r2s).mean(axis=0)
  
      bestAlpha, bestr2 = sorted(
          zip(alphaMap.keys(), r2_mean), key=lambda t: -t[1]
      )[0]
  
      y_hat = pd.Series(index=std_labeldf.index)
      for group in groups:
          ids = group2ids[group]
          X_in = cov_X[headersToKeep].loc[ids, :].to_numpy()
          X_out = cov_X[headersToKeep].drop(ids, axis="rows")
          Y_out = std_labeldf[testLabel].loc[X_out.index].to_numpy()
          XtX_out = X_out.to_numpy().T @ X_out.to_numpy()
          XtY_out = X_out.to_numpy().T @ Y_out
          d = np.concatenate(
              [
                  np.ones(n_cov),
                  np.ones(XtX_out.shape[1] - n_cov)
                  * alphaMap[bestAlpha],
              ]
          )
          b = np.linalg.inv(XtX_out + np.diag(d)) @ XtY_out
          group_y_hats = X_in @ b
          for s, y in zip(ids, group_y_hats):
              y_hat[s] = y
  
      return bestAlpha, bestr2, y_hat.to_numpy()
  
imports: from glow.wgr.ridge_reduction import *
  from glow.wgr.ridge_regression import *
  from glow.wgr.ridge_udfs import *
  from glow.wgr.model_functions import _fill_na_and_standardize
  import numpy
  import pandas
  from pyspark.sql.functions import *
  import math
label_desc: Use image node_id 10 for calling a global function with example usage: __calculate_y_hat(X_base, group2ids, testLabel, cov) and returns: bestAlpha,  bestr2,  y_hat