code: def affinity_matrix(test_specs):
      """Generate a random user/item affinity matrix. By increasing the likelihood of 0 elements we simulate
      a typical recommending situation where the input matrix is highly sparse.
  
      Args:
          test_specs["users"] (int): number of users (rows).
          test_specs["items"] (int): number of items (columns).
          test_specs["ratings"] (int): rating scale, e.g. 5 meaning rates are from 1 to 5.
          test_specs["spars"]: probability of obtaining zero. This roughly corresponds to the sparseness.
                 of the generated matrix. If spars = 0 then the affinity matrix is dense.
  
      Returns:
          np.array: sparse user/affinity matrix of integers.
  
      """
  
      np.random.seed(test_specs["seed"])
  
      # uniform probability for the 5 ratings
      s = [
          (1 - test_specs["spars"]) / test_specs["ratings"]
      ] * test_specs["ratings"]
      s.append(test_specs["spars"])
      P = s[::-1]
  
      # generates the user/item affinity matrix. Ratings are from 1 to 5, with 0s denoting unrated items
      X = np.random.choice(
          test_specs["ratings"] + 1,
          (test_specs["users"], test_specs["items"]),
          p=P,
      )
  
      Xtr, Xtst = numpy_stratified_split(
          X, ratio=test_specs["ratio"], seed=test_specs["seed"]
      )
  
      return Xtr, Xtst
  
imports: import calendar
  import datetime
  import os
  from pathlib import Path
  from tempfile import TemporaryDirectory
  import numpy
  import pandas
  import pytest
  from sklearn.model_selection import train_test_split
  from recommenders.utils.constants import DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_TIMESTAMP_COL
  from recommenders.datasets.python_splitters import numpy_stratified_split
  from recommenders.datasets.python_splitters import python_chrono_split
  from recommenders.utils.spark_utils import start_or_get_spark
label_desc: Use image node_id 24 for calling a global function with example usage: affinity_matrix(test_specs) and returns: Xtr,  Xtst