code: def rating_eval(
      model, metrics, test_set, user_based=False, verbose=False
  ):
      """Evaluate model on provided rating metrics.
  
      Parameters
      ----------
      model: :obj:`cornac.models.Recommender`, required
          Recommender model to be evaluated.
  
      metrics: :obj:`iterable`, required
          List of rating metrics :obj:`cornac.metrics.RatingMetric`.
  
      test_set: :obj:`cornac.data.Dataset`, required
          Dataset to be used for evaluation.
  
      user_based: bool, optional, default: False
          Evaluation mode. Whether results are averaging based on number of users or number of ratings.
  
      verbose: bool, optional, default: False
          Output evaluation progress.
  
      Returns
      -------
      res: (List, List)
          Tuple of two lists:
           - average result for each of the metrics
           - average result per user for each of the metrics
  
      """
  
      if len(metrics) == 0:
          return [], []
  
      avg_results = []
      user_results = []
  
      (u_indices, i_indices, r_values) = test_set.uir_tuple
      r_preds = np.fromiter(
          tqdm(
              (
                  model.rate(user_idx, item_idx).item()
                  for user_idx, item_idx in zip(u_indices, i_indices)
              ),
              desc="Rating",
              disable=not verbose,
              miniters=100,
              total=len(u_indices),
          ),
          dtype="float",
      )
  
      gt_mat = test_set.csr_matrix
      pd_mat = csr_matrix(
          (r_preds, (u_indices, i_indices)), shape=gt_mat.shape
      )
  
      test_user_indices = set(u_indices)
      for mt in metrics:
          if user_based:  # averaging over users
              user_results.append(
                  {
                      user_idx: mt.compute(
                          gt_ratings=gt_mat.getrow(user_idx).data,
                          pd_ratings=pd_mat.getrow(user_idx).data,
                      ).item()
                      for user_idx in test_user_indices
                  }
              )
              avg_results.append(
                  sum(user_results[-1].values()) / len(user_results[-1])
              )
          else:  # averaging over ratings
              user_results.append({})
              avg_results.append(
                  mt.compute(gt_ratings=r_values, pd_ratings=r_preds)
              )
  
      return avg_results, user_results
  
imports: from collections import OrderedDict
  import time
  import numpy
  from scipy.sparse import csr_matrix
  from tqdm.auto import tqdm
  from ..data import FeatureModality
  from ..data import TextModality, ReviewModality
  from ..data import ImageModality
  from ..data import GraphModality
  from ..data import SentimentModality
  from ..data import Dataset
  from ..metrics import RatingMetric
  from ..metrics import RankingMetric
  from ..experiment.result import Result
  from ..utils import get_rng
label_desc: Use image node_id 1 for calling a global function with example usage: rating_eval(model, metrics, test_set, user_based, verbose) and returns: avg_results,  user_results, list,  list