code: def xval(
      lhs: np.ndarray, rhs: np.ndarray, log: bool = True, folds: int = 5
  ) -> None:
      lhs = np.asarray(lhs)
      rhs = np.asarray(rhs)
      pcg = np.random.PCG64(849756746597530743027509)
      gen = np.random.Generator(pcg)
      nobs = lhs.shape[0]
      idx = gen.permutation(nobs)
      predictions = np.empty((nobs, 6))
      for fold in range(folds):
          right = int(fold * nobs / folds)
          left = int((fold + 1) * nobs / folds)
          locs = idx[np.r_[np.arange(0, right), np.arange(left, nobs)]]
          end = nobs if fold == folds - 1 else left
          pred_loc = idx[np.arange(right, end)]
          pred_rhs = rhs[pred_loc]
          sm = OLS(lhs[locs], rhs[locs, :3]).fit()
          predictions[pred_loc, 0] = pred_rhs[:, :3] @ sm.params
          lg = OLS(lhs[locs], rhs[locs]).fit()
          predictions[pred_loc, 1] = pred_rhs @ lg.params
          if log and np.all(np.sign(lhs) == np.sign(lhs)[0]):
              log_lhs = np.log(np.abs(lhs))
              sgn = np.sign(lhs[0])
              sm_log = OLS(log_lhs[locs], rhs[locs, :3]).fit()
              sigma2 = (sm_log.resid**2).mean()
              predictions[pred_loc, 2] = sgn * np.exp(
                  pred_rhs[:, :3] @ sm_log.params
              )
              predictions[pred_loc, 3] = sgn * np.exp(
                  pred_rhs[:, :3] @ sm_log.params + sigma2 / 2
              )
  
              lg_log = OLS(log_lhs[locs], rhs[locs]).fit()
              sigma2 = (lg_log.resid**2).mean()
              predictions[pred_loc, 4] = sgn * np.exp(
                  pred_rhs @ lg_log.params
              )
              predictions[pred_loc, 5] = sgn * np.exp(
                  pred_rhs @ lg_log.params + sigma2 / 2
              )
      errors = lhs[:, None] - predictions
      best = int(np.argmin(errors.var(0)))
      WINS[best] += 1
  
imports: from __future__ import annotations
  from collections import defaultdict
  import glob
  from itertools import product
  import os
  from typing import NamedTuple, cast
  from black import FileMode, TargetVersion, format_file_contents
  import matplotlib.backends.backend_pdf
  import matplotlib.pyplot
  import numpy
  import pandas
  from phillips_ouliaris import FILE_TYPES, ROOT, TRENDS
  from scipy import stats
  import seaborn
  from shared import format_dict
  from statsmodels.regression.linear_model import OLS, WLS
label_desc: Use image node_id 1 for calling a global function with example usage: xval(lhs, rhs, log, folds) without return types