class_docstr: Simple Algorithm for Recommendations (SAR) implementation
  
  SAR is a fast scalable adaptive algorithm for personalized recommendations based on user transaction history
  and items description. The core idea behind SAR is to recommend items like those that a user already has
  demonstrated an affinity to. It does this by 1) estimating the affinity of users for items, 2) estimating
  similarity across items, and then 3) combining the estimates to generate a set of recommendations for a given user.
class_docstr_tok: ["Simple","Algorithm","for","Recommendations","(","SAR",")","implementation","SAR","is","a","fast","scalable","adaptive","algorithm","for","personalized","recommendations","based","on","user","transaction","history","and","items","description",".","The","core","idea","behind","SAR","is","to","recommend","items","like","those","that","a","user","already","has","demonstrated","an","affinity","to",".","It","does","this","by","1",")","estimating","the","affinity","of","users","for","items",",","2",")","estimating","similarity","across","items",",","and","then","3",")","combining","the","estimates","to","generate","a","set","of","recommendations","for","a","given","user","."]
docstr: Recommend top K items for all users which are in the test set
  
  Args:
      test (pandas.DataFrame): users to test
      top_k (int): number of top items to recommend
      sort_top_k (bool): flag to sort top k results
      remove_seen (bool): flag to remove items seen in training from recommendation
  
  Returns:
      pandas.DataFrame: top k recommendation items for each user
docstr_tok: ["Recommend","top","K","items","for","all","users","which","are","in","the","test","set","Args",":","test","(","pandas.DataFrame",")",":","users","to","test","top_k","(","int",")",":","number","of","top","items","to","recommend","sort_top_k","(","bool",")",":","flag","to","sort","top","k","results","remove_seen","(","bool",")",":","flag","to","remove","items","seen","in","training","from","recommendation","Returns",":","pandas.DataFrame",":","top","k","recommendation","items","for","each","user"]
code: def recommend_k_items(
      self, test, top_k=10, sort_top_k=True, remove_seen=False
  ):
      """Recommend top K items for all users which are in the test set
  
      Args:
          test (pandas.DataFrame): users to test
          top_k (int): number of top items to recommend
          sort_top_k (bool): flag to sort top k results
          remove_seen (bool): flag to remove items seen in training from recommendation
  
      Returns:
          pandas.DataFrame: top k recommendation items for each user
      """
  
      test_scores = self.score(test, remove_seen=remove_seen)
  
      top_items, top_scores = get_top_k_scored_items(
          scores=test_scores, top_k=top_k, sort_top_k=sort_top_k
      )
  
      df = pd.DataFrame(
          {
              self.col_user: np.repeat(
                  test[self.col_user].drop_duplicates().values,
                  top_items.shape[1],
              ),
              self.col_item: [
                  self.index2item[item] for item in top_items.flatten()
              ],
              self.col_prediction: top_scores.flatten(),
          }
      )
  
      # drop invalid items
      return df.replace(-np.inf, np.nan).dropna()
  
file_path: recommenders/recommenders/models/sar/sar_singlenode.py
imports: import numpy
  import pandas
  import logging
  from scipy import sparse
  from recommenders.utils.python_utils import cosine_similarity, inclusion_index, jaccard, lexicographers_mutual_information, lift, mutual_information, exponential_decay, get_top_k_scored_items, rescale
  from recommenders.utils import constants
label_desc: Use image node_id 11 for calling the SARSingleNode obj's underlying member method code with example usage: obj.recommend_k_items(test, top_k, sort_top_k, remove_seen) and returns: df