class_docstr: Spark Evaluator for diversity, coverage, novelty, serendipity
class_docstr_tok: ["Spark","Evaluator","for","diversity",",","coverage",",","novelty",",","serendipity"]
docstr: Calculate distributional coverage for recommendations across all users.
  The metric definition is based on formula (21) in the following reference:
  
  :Citation:
  
      G. Shani and A. Gunawardana, Evaluating Recommendation Systems,
      Recommender Systems Handbook pp. 257-297, 2010.
  
  Returns:
      float: distributional coverage
docstr_tok: ["Calculate","distributional","coverage","for","recommendations","across","all","users",".","The","metric","definition","is","based","on","formula","(","21",")","in","the","following","reference",":",":","Citation",":","G.","Shani","and","A.","Gunawardana",",","Evaluating","Recommendation","Systems",",","Recommender","Systems","Handbook","pp",".","257-297",",","2010",".","Returns",":","float",":","distributional","coverage"]
code: def distributional_coverage(self):
      """Calculate distributional coverage for recommendations across all users.
      The metric definition is based on formula (21) in the following reference:
  
      :Citation:
  
          G. Shani and A. Gunawardana, Evaluating Recommendation Systems,
          Recommender Systems Handbook pp. 257-297, 2010.
  
      Returns:
          float: distributional coverage
      """
      # In reco_df, how  many times each col_item is being recommended
      df_itemcnt_reco = self.reco_df.groupBy(self.col_item).count()
  
      # the number of total recommendations
      count_row_reco = self.reco_df.count()
      df_entropy = df_itemcnt_reco.withColumn(
          "p(i)", F.col("count") / count_row_reco
      ).withColumn("entropy(i)", F.col("p(i)") * F.log2(F.col("p(i)")))
      # distributional coverage
      d_coverage = -df_entropy.agg(F.sum("entropy(i)")).collect()[0][0]
  
      return d_coverage
  
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 16 for calling the SparkDiversityEvaluation obj's underlying member method code with example usage: obj.distributional_coverage() and returns: d_coverage