code: def personalization(predicted: List[list]) -> float:
      """
      Personalization measures recommendation similarity across users.
      A high score indicates good personalization (user's lists of recommendations are different).
      A low score indicates poor personalization (user's lists of recommendations are very similar).
      A model is "personalizing" well if the set of recommendations for each user is different.
      Parameters:
      ----------
      predicted : a list of lists
          Ordered predictions
          example: [['X', 'Y', 'Z'], ['X', 'Y', 'Z']]
      Returns:
      -------
          The personalization score for all recommendations.
      """
  
      def make_rec_matrix(predicted: List[list]) -> sp.csr_matrix:
          df = (
              pd.DataFrame(data=predicted)
              .reset_index()
              .melt(
                  id_vars="index",
                  value_name="item",
              )
          )
          df = df[["index", "item"]].pivot(
              index="index", columns="item", values="item"
          )
          df = pd.notna(df) * 1
          rec_matrix = sp.csr_matrix(df.values)
          return rec_matrix
  
      # create matrix for recommendations
      predicted = np.array(predicted)
      rec_matrix_sparse = make_rec_matrix(predicted)
  
      # calculate similarity for every user's recommendation list
      similarity = cosine_similarity(
          X=rec_matrix_sparse, dense_output=False
      )
  
      # calculate average similarity
      dim = similarity.shape[0]
      personalization = (similarity.sum() - dim) / (dim * (dim - 1))
      return 1 - personalization
  
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 8 for calling a global function with example usage: personalization(predicted) and returns: unknown, rec_matrix