code: def test_irls_one_step():
      def irls_fit(X, y, alpha, n_cov, beta_cov):
          if n_cov > 0:
              beta = np.zeros(X.shape[1])
              beta[:n_cov] = beta_cov
          else:
              beta = np.zeros(X.shape[1])
  
          z = X @ beta
          p = sigmoid(z)
          xtgx = (X.T * (p * (1 - p))) @ X
          xty = X.T @ (p - y)
          loss_old = log_loss(p.reshape(-1, 1), y.reshape(-1, 1))[0]
  
          data = {
              "xtgx": list(xtgx),
              "xty": list(xty),
              "beta": list(beta),
          }
  
          pdf = pd.DataFrame(data)
  
          dloss = loss_old * 10
          tol = 1e-5
          n_steps = 0
          while dloss > tol and n_steps <= 10000:
              beta = irls_one_step(pdf, alpha, n_cov)
              z = X @ beta
              p = sigmoid(z)
              xtgx = (X.T * (p * (1 - p))) @ X
              xty = X.T @ (p - y)
              loss = log_loss(p.reshape(-1, 1), y.reshape(-1, 1))[0]
              dloss = loss_old - loss
              loss_old = loss
  
              data = {
                  "xtgx": list(xtgx),
                  "xty": list(xty),
                  "beta": list(beta),
              }
  
              pdf = pd.DataFrame(data)
              n_steps += 1
  
          return beta
  
      X_raw, y = load_breast_cancer(return_X_y=True)
      mu, sig = X_raw.mean(axis=0), X_raw.std(axis=0)
      X = (X_raw - mu) / sig
      alphas = [10, 30, 100, 300, 1000, 3000]
      for a in alphas:
          model_skl = LogisticRegression(C=1 / a, fit_intercept=True)
          model_skl.fit(X, y)
          X_with_int = np.column_stack([np.ones(X.shape[0]), X])
          beta_irls = irls_fit(
              X_with_int, y, a, 1, model_skl.intercept_
          )
          beta_skl = np.concatenate(
              [model_skl.intercept_, model_skl.coef_.ravel()]
          )
          assert np.allclose(beta_irls, beta_skl, 0.01)
  
imports: from glow.wgr.model_functions import *
  from glow.wgr.model_functions import _prepare_covariates, _prepare_labels_and_warn
  import math
  import numpy
  import pandas
  from pyspark.sql import Row
  import pytest
  from sklearn.linear_model import LogisticRegression
  from sklearn.datasets import load_breast_cancer
label_desc: Use image node_id 15 for calling a global function with example usage: test_irls_one_step() and returns: beta