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: Output SAR scores for only the users-items pairs which are in the test set
  
  Args:
      test (pandas.DataFrame): DataFrame that contains users and items to test
  
  Returns:
      pandas.DataFrame: DataFrame contains the prediction results
docstr_tok: ["Output","SAR","scores","for","only","the","users-items","pairs","which","are","in","the","test","set","Args",":","test","(","pandas.DataFrame",")",":","DataFrame","that","contains","users","and","items","to","test","Returns",":","pandas.DataFrame",":","DataFrame","contains","the","prediction","results"]
code: def predict(self, test):
      """Output SAR scores for only the users-items pairs which are in the test set
  
      Args:
          test (pandas.DataFrame): DataFrame that contains users and items to test
  
      Returns:
          pandas.DataFrame: DataFrame contains the prediction results
      """
  
      test_scores = self.score(test)
      user_ids = np.asarray(
          list(
              map(
                  lambda user: self.user2index.get(user, np.NaN),
                  test[self.col_user].values,
              )
          )
      )
  
      # create mapping of new items to zeros
      item_ids = np.asarray(
          list(
              map(
                  lambda item: self.item2index.get(item, np.NaN),
                  test[self.col_item].values,
              )
          )
      )
      nans = np.isnan(item_ids)
      if any(nans):
          logger.warning(
              "Items found in test not seen during training, new items will have score of 0"
          )
          test_scores = np.append(
              test_scores, np.zeros((self.n_users, 1)), axis=1
          )
          item_ids[nans] = self.n_items
          item_ids = item_ids.astype("int64")
  
      df = pd.DataFrame(
          {
              self.col_user: test[self.col_user].values,
              self.col_item: test[self.col_item].values,
              self.col_prediction: test_scores[user_ids, item_ids],
          }
      )
      return df
  
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 12 for calling the SARSingleNode obj's underlying member method code with example usage: obj.predict(test) and returns: df