class_docstr: Spark Evaluator for diversity, coverage, novelty, serendipity
class_docstr_tok: ["Spark","Evaluator","for","diversity",",","coverage",",","novelty",",","serendipity"]
docstr: Get pairwise combinations of items per user (ignoring duplicate pairs [1,2] == [2,1])
docstr_tok: ["Get","pairwise","combinations","of","items","per","user","(","ignoring","duplicate","pairs","[","1,2","]","==","[","2,1","]",")"]
code: def _get_pairwise_items(self, df):
      """Get pairwise combinations of items per user (ignoring duplicate pairs [1,2] == [2,1])"""
      return (
          df.select(self.col_user, F.col(self.col_item).alias("i1"))
          .join(
              df.select(
                  F.col(self.col_user).alias("_user"),
                  F.col(self.col_item).alias("i2"),
              ),
              (F.col(self.col_user) == F.col("_user"))
              & (F.col("i1") <= F.col("i2")),
          )
          .select(self.col_user, "i1", "i2")
      )
  
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 2 for calling the SparkDiversityEvaluation obj's underlying member method code with example usage: obj._get_pairwise_items(df) and returns: df