code: def _apk(actual: list, predicted: list, k=10) -> float:
      """
      Computes the average precision at k.
      Parameters
      ----------
      actual : list
          A list of actual items to be predicted
      predicted : list
          An ordered list of predicted items
      k : int, default = 10
          Number of predictions to consider
      Returns:
      -------
      score : float
          The average precision at k.
      """
      if not predicted or not actual:
          return 0.0
  
      if len(predicted) > k:
          predicted = predicted[:k]
  
      score = 0.0
      true_positives = 0.0
  
      for i, p in enumerate(predicted):
          if p in actual and p not in predicted[:i]:
              max_ix = min(i + 1, len(predicted))
              score += _precision(predicted[:max_ix], actual)
              true_positives += 1
  
      if score == 0.0:
          return 0.0
  
      return score / true_positives
  
imports: import random
  from itertools import product
  from math import sqrt
  from typing import List
  import matplotlib.pyplot
  import numpy
  import pandas
  import scipy.sparse
  from sklearn.metrics import confusion_matrix, mean_squared_error
  from sklearn.metrics.pairwise import cosine_similarity
  import warnings
label_desc: Use image node_id 5 for calling a global function with example usage: _apk(actual, predicted, k) and returns: unknown, int, int