code: def _get_intralist_similarity(
      train_df,
      reco_df,
      item_feature_df=None,
      item_sim_measure=DEFAULT_ITEM_SIM_MEASURE,
      col_item_features=DEFAULT_ITEM_FEATURES_COL,
      col_user=DEFAULT_USER_COL,
      col_item=DEFAULT_ITEM_COL,
      col_sim=DEFAULT_SIMILARITY_COL,
  ):
      """Intra-list similarity from
  
      :Citation:
  
          "Improving Recommendation Lists Through Topic Diversification",
          Ziegler, McNee, Konstan and Lausen, 2005.
      """
      pairs = _get_pairwise_items(reco_df, col_user, col_item)
      similarity_df = _get_cosine_similarity(
          train_df,
          item_feature_df,
          item_sim_measure,
          col_item_features,
          col_user,
          col_item,
          col_sim,
      )
      # Fillna(0) is needed in the cases where similarity_df does not have an entry for a pair of items.
      # e.g. i1 and i2 have never occurred together.
  
      item_pair_sim = pairs.merge(
          similarity_df, on=["i1", "i2"], how="left"
      )
      item_pair_sim[col_sim].fillna(0, inplace=True)
      item_pair_sim = item_pair_sim.loc[
          item_pair_sim["i1"] != item_pair_sim["i2"]
      ].reset_index(drop=True)
      df_intralist_similarity = (
          item_pair_sim.groupby([col_user])
          .agg({col_sim: "mean"})
          .reset_index()
      )
      df_intralist_similarity.columns = [col_user, "avg_il_sim"]
  
      return df_intralist_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 23 for calling a global function with example usage: _get_intralist_similarity(train_df, reco_df, item_feature_df, item_sim_measure, col_item_features, col_user, col_item, col_sim) and returns: df_intralist_similarity