code: def _get_cooccurrence_similarity(
      train_df,
      col_user=DEFAULT_USER_COL,
      col_item=DEFAULT_ITEM_COL,
      col_sim=DEFAULT_SIMILARITY_COL,
  ):
      """Cosine similarity metric from
  
      :Citation:
  
          Y.C. Zhang, D.Ó. Séaghdha, D. Quercia and T. Jambor, Auralist:
          introducing serendipity into music recommendation, WSDM 2012
  
      The item indexes in the result are such that i1 <= i2.
      """
      pairs = _get_pairwise_items(train_df, col_user, col_item)
      pairs_count = pd.DataFrame(
          {"count": pairs.groupby(["i1", "i2"]).size()}
      ).reset_index()
      item_count = pd.DataFrame(
          {"count": train_df.groupby([col_item]).size()}
      ).reset_index()
      item_count["item_sqrt_count"] = item_count["count"] ** 0.5
      item_co_occur = pairs_count.merge(
          item_count[[col_item, "item_sqrt_count"]],
          left_on=["i1"],
          right_on=[col_item],
      ).drop(columns=[col_item])
  
      item_co_occur.columns = ["i1", "i2", "count", "i1_sqrt_count"]
  
      item_co_occur = item_co_occur.merge(
          item_count[[col_item, "item_sqrt_count"]],
          left_on=["i2"],
          right_on=[col_item],
      ).drop(columns=[col_item])
      item_co_occur.columns = [
          "i1",
          "i2",
          "count",
          "i1_sqrt_count",
          "i2_sqrt_count",
      ]
  
      item_co_occur[col_sim] = item_co_occur["count"] / (
          item_co_occur["i1_sqrt_count"]
          * item_co_occur["i2_sqrt_count"]
      )
      df_cosine_similarity = (
          item_co_occur[["i1", "i2", col_sim]]
          .sort_values(["i1", "i2"])
          .reset_index(drop=True)
      )
  
      return df_cosine_similarity
  
imports: import numpy
  import pandas
  from functools import wraps
  from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score, explained_variance_score, roc_auc_score, log_loss
  from recommenders.utils.constants import DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_PREDICTION_COL, DEFAULT_RELEVANCE_COL, DEFAULT_SIMILARITY_COL, DEFAULT_ITEM_FEATURES_COL, DEFAULT_ITEM_SIM_MEASURE, DEFAULT_K, DEFAULT_THRESHOLD
  from recommenders.datasets.pandas_df_utils import has_columns, has_same_base_dtype, lru_cache_df
label_desc: Use image node_id 21 for calling a global function with example usage: _get_cooccurrence_similarity(train_df, col_user, col_item, col_sim) and returns: df_cosine_similarity