class_docstr: Spark Evaluator for diversity, coverage, novelty, serendipity
class_docstr_tok: ["Spark","Evaluator","for","diversity",",","coverage",",","novelty",",","serendipity"]
docstr: Calculate the average novelty in a list of recommended items (this assumes that the recommendation list
  is already computed). Follows section 5 from
  
  :Citation:
  
      P. Castells, S. Vargas, and J. Wang, Novelty and diversity metrics for recommender systems:
      choice, discovery and relevance, ECIR 2011
  
  Returns:
      pyspark.sql.dataframe.DataFrame: A dataframe with following columns: novelty.
docstr_tok: ["Calculate","the","average","novelty","in","a","list","of","recommended","items","(","this","assumes","that","the","recommendation","list","is","already","computed",")",".","Follows","section","5","from",":","Citation",":","P.","Castells",",","S.","Vargas",",","and","J.","Wang",",","Novelty","and","diversity","metrics","for","recommender","systems",":","choice",",","discovery","and","relevance",",","ECIR","2011","Returns",":","pyspark.sql.dataframe.DataFrame",":","A","dataframe","with","following","columns",":","novelty","."]
code: def novelty(self):
      """Calculate the average novelty in a list of recommended items (this assumes that the recommendation list
      is already computed). Follows section 5 from
  
      :Citation:
  
          P. Castells, S. Vargas, and J. Wang, Novelty and diversity metrics for recommender systems:
          choice, discovery and relevance, ECIR 2011
  
      Returns:
          pyspark.sql.dataframe.DataFrame: A dataframe with following columns: novelty.
      """
      if self.avg_novelty is None:
          self.df_item_novelty = self.historical_item_novelty()
          n_recommendations = self.reco_df.count()
          self.avg_novelty = (
              self.reco_df.groupBy(self.col_item)
              .count()
              .join(self.df_item_novelty, self.col_item)
              .selectExpr("sum(count * item_novelty)")
              .first()[0]
              / n_recommendations
          )
      return self.avg_novelty
  
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 11 for calling the SparkDiversityEvaluation obj's underlying member method code with example usage: obj.novelty() and returns: self