class_docstr: Spark Ranking Evaluator
class_docstr_tok: ["Spark","Ranking","Evaluator"]
docstr: Calculate ranking metrics.
docstr_tok: ["Calculate","ranking","metrics","."]
code: def _calculate_metrics(self):
      """Calculate ranking metrics."""
      self._items_for_user_pred = self.rating_pred
  
      self._items_for_user_true = (
          self.rating_true.groupBy(self.col_user)
          .agg(
              expr(
                  "collect_list(" + self.col_item + ") as ground_truth"
              )
          )
          .select(self.col_user, "ground_truth")
      )
  
      self._items_for_user_all = self._items_for_user_pred.join(
          self._items_for_user_true, on=self.col_user
      ).drop(self.col_user)
  
      return RankingMetrics(self._items_for_user_all.rdd)
  
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 SparkRankingEvaluation obj's underlying member method code with example usage: obj._calculate_metrics() and returns: RankingMetrics