code: def _auc(
      model,
      ground_truth,
      train=None,
      user_features=None,
      item_features=None,
  ):
      ground_truth = ground_truth.tocsr()
  
      no_users, no_items = ground_truth.shape
  
      pid_array = np.arange(no_items, dtype=np.int32)
  
      scores = []
  
      if train is not None:
          train = train.tocsr()
  
      for user_id, row in enumerate(ground_truth):
          uid_array = np.empty(no_items, dtype=np.int32)
          uid_array.fill(user_id)
          predictions = model.predict(
              uid_array,
              pid_array,
              user_features=user_features,
              item_features=item_features,
              num_threads=4,
          )
  
          true_pids = row.indices[row.data == 1]
  
          grnd = np.zeros(no_items, dtype=np.int32)
          grnd[true_pids] = 1
  
          if not len(true_pids):
              continue
  
          if train is not None:
              train_indices = train[user_id].indices
              not_in_train = np.array(
                  [x not in train_indices for x in range(no_items)]
              )
              scores.append(
                  roc_auc_score(
                      grnd[not_in_train], predictions[not_in_train]
                  )
              )
          else:
              scores.append(roc_auc_score(grnd, predictions))
  
      return scores
  
file_path: lightfm/tests/test_evaluation.py
imports: import numpy
  import pytest
  import scipy.sparse
  from sklearn.metrics import roc_auc_score
  from lightfm.lightfm import LightFM
  from lightfm import evaluation
label_desc: Use image node_id 4 for calling a global function with example usage: _auc(model, ground_truth, train, user_features, item_features) and returns: scores