code: def f1_score_at_k(
      predicted_ranks, test_interactions, k=10, preserve_rows=False
  ):
      """
      :param model: TensorRec
      A trained TensorRec model.
      :param test_interactions: scipy.sparse matrix
      Test interactions matrix of shape [n_users, n_items]
      :param user_features: scipy.sparse matrix
      User features matrix of shape [n_users, n_user_features]
      :param item_features: scipy.sparse matrix
      Item features matrix of shape [n_items, n_item_features]
      :param k: int
      The rank at which to stop evaluating recall.
      :param preserve_rows: bool
      If True, a value of 0 will be returned for every user without test interactions.
      If False, only users with test interactions will be returned.
      :return: np.array
      """
      p_at_k = precision_at_k(
          predicted_ranks=predicted_ranks,
          test_interactions=test_interactions,
          k=k,
          preserve_rows=preserve_rows,
      )
      r_at_k = recall_at_k(
          predicted_ranks=predicted_ranks,
          test_interactions=test_interactions,
          k=k,
          preserve_rows=preserve_rows,
      )
  
      mean_p = np.mean(p_at_k)
      mean_r = np.mean(r_at_k)
  
      f1_score = (2.0 * mean_p * mean_r) / (mean_p + mean_r)
      return f1_score
  
file_path: tensorrec/tensorrec/eval.py
imports: import numpy
  import scipy.sparse
  from .tensorrec import TensorRec
label_desc: Use image node_id 7 for calling a global function with example usage: f1_score_at_k(predicted_ranks, test_interactions, k, preserve_rows) and returns: f1_score