class_docstr: Spark Evaluator for diversity, coverage, novelty, serendipity
class_docstr_tok: ["Spark","Evaluator","for","diversity",",","coverage",",","novelty",",","serendipity"]
docstr: Calculate average serendipity for each user's recommendations.
  
  Returns:
      pyspark.sql.dataframe.DataFrame: A dataframe with following columns: col_user, user_serendipity.
docstr_tok: ["Calculate","average","serendipity","for","each","user","'s","recommendations",".","Returns",":","pyspark.sql.dataframe.DataFrame",":","A","dataframe","with","following","columns",":","col_user",",","user_serendipity","."]
code: def user_serendipity(self):
      """Calculate average serendipity for each user's recommendations.
  
      Returns:
          pyspark.sql.dataframe.DataFrame: A dataframe with following columns: col_user, user_serendipity.
      """
      if self.df_user_serendipity is None:
          self.df_user_item_serendipity = self.user_item_serendipity()
          self.df_user_serendipity = (
              self.df_user_item_serendipity.groupBy(self.col_user)
              .agg(
                  F.mean("user_item_serendipity").alias(
                      "user_serendipity"
                  )
              )
              .orderBy(self.col_user)
          )
      return self.df_user_serendipity
  
imports: import numpy
  from recommenders.utils.constants import DEFAULT_PREDICTION_COL, DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_RELEVANCE_COL, DEFAULT_SIMILARITY_COL, DEFAULT_ITEM_FEATURES_COL, DEFAULT_ITEM_SIM_MEASURE, DEFAULT_TIMESTAMP_COL, DEFAULT_K, DEFAULT_THRESHOLD
label_desc: Use image node_id 13 for calling the SparkDiversityEvaluation obj's underlying member method code with example usage: obj.user_serendipity() and returns: self