class_docstr: Spark Evaluator for diversity, coverage, novelty, serendipity
class_docstr_tok: ["Spark","Evaluator","for","diversity",",","coverage",",","novelty",",","serendipity"]
docstr: Calculate average diversity of recommendations for each user.
  The metric definition is based on formula (3) in the following reference:
  
  :Citation:
  
      Y.C. Zhang, D.Ó. Séaghdha, D. Quercia and T. Jambor, Auralist:
      introducing serendipity into music recommendation, WSDM 2012
  
  Returns:
      pyspark.sql.dataframe.DataFrame: A dataframe with the following columns: col_user, user_diversity.
docstr_tok: ["Calculate","average","diversity","of","recommendations","for","each","user",".","The","metric","definition","is","based","on","formula","(","3",")","in","the","following","reference",":",":","Citation",":","Y.C",".","Zhang",",","D.\u00d3",".","S\u00e9aghdha",",","D.","Quercia","and","T.","Jambor",",","Auralist",":","introducing","serendipity","into","music","recommendation",",","WSDM","2012","Returns",":","pyspark.sql.dataframe.DataFrame",":","A","dataframe","with","the","following","columns",":","col_user",",","user_diversity","."]
code: def user_diversity(self):
      """Calculate average diversity of recommendations for each user.
      The metric definition is based on formula (3) in the following reference:
  
      :Citation:
  
          Y.C. Zhang, D.Ó. Séaghdha, D. Quercia and T. Jambor, Auralist:
          introducing serendipity into music recommendation, WSDM 2012
  
      Returns:
          pyspark.sql.dataframe.DataFrame: A dataframe with the following columns: col_user, user_diversity.
      """
      if self.df_user_diversity is None:
          self.df_intralist_similarity = self._get_intralist_similarity(
              self.reco_df
          )
          self.df_user_diversity = (
              self.df_intralist_similarity.withColumn(
                  "user_diversity", 1 - F.col("avg_il_sim")
              )
              .select(self.col_user, "user_diversity")
              .orderBy(self.col_user)
          )
      return self.df_user_diversity
  
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 8 for calling the SparkDiversityEvaluation obj's underlying member method code with example usage: obj.user_diversity() and returns: self