code: def _single_list_similarity(
      predicted: list, feature_df: pd.DataFrame, u: int
  ) -> float:
      """
      Computes the intra-list similarity for a single list of recommendations.
      Parameters
      ----------
      predicted : a list
          Ordered predictions
          Example: ['X', 'Y', 'Z']
      feature_df: dataframe
          A dataframe with one hot encoded or latent features.
          The dataframe should be indexed by the id used in the recommendations.
      Returns:
      -------
      ils_single_user: float
          The intra-list similarity for a single list of recommendations.
      """
      # exception predicted list empty
      if not (predicted):
          raise Exception(
              "Predicted list is empty, index: {0}".format(u)
          )
  
      # get features for all recommended items
      recs_content = feature_df.loc[predicted]
      recs_content = recs_content.dropna()
      recs_content = sp.csr_matrix(recs_content.values)
  
      # calculate similarity scores for all items in list
      similarity = cosine_similarity(X=recs_content, dense_output=False)
  
      # get indicies for upper right triangle w/o diagonal
      upper_right = np.triu_indices(similarity.shape[0], k=1)
  
      # calculate average similarity score of all recommended items in list
      ils_single_user = np.mean(similarity[upper_right])
      return ils_single_user
  
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 9 for calling a global function with example usage: _single_list_similarity(predicted, feature_df, u) and returns: ils_single_user