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: Score all items for test users.
  
  Args:
      test (pandas.DataFrame): user to test
      remove_seen (bool): flag to remove items seen in training from recommendation
  
  Returns:
      numpy.ndarray: Value of interest of all items for the users.
docstr_tok: ["Score","all","items","for","test","users",".","Args",":","test","(","pandas.DataFrame",")",":","user","to","test","remove_seen","(","bool",")",":","flag","to","remove","items","seen","in","training","from","recommendation","Returns",":","numpy.ndarray",":","Value","of","interest","of","all","items","for","the","users","."]
code: def score(self, test, remove_seen=False):
      """Score all items for test users.
  
      Args:
          test (pandas.DataFrame): user to test
          remove_seen (bool): flag to remove items seen in training from recommendation
  
      Returns:
          numpy.ndarray: Value of interest of all items for the users.
      """
  
      # get user / item indices from test set
      user_ids = list(
          map(
              lambda user: self.user2index.get(user, np.NaN),
              test[self.col_user].unique(),
          )
      )
      if any(np.isnan(user_ids)):
          raise ValueError(
              "SAR cannot score users that are not in the training set"
          )
  
      # calculate raw scores with a matrix multiplication
      logger.info("Calculating recommendation scores")
      test_scores = self.user_affinity[user_ids, :].dot(
          self.item_similarity
      )
  
      # ensure we're working with a dense ndarray
      if isinstance(test_scores, sparse.spmatrix):
          test_scores = test_scores.toarray()
  
      if self.normalize:
          counts = self.unity_user_affinity[user_ids, :].dot(
              self.item_similarity
          )
          user_min_scores = (
              np.tile(
                  counts.min(axis=1)[:, np.newaxis],
                  test_scores.shape[1],
              )
              * self.rating_min
          )
          user_max_scores = (
              np.tile(
                  counts.max(axis=1)[:, np.newaxis],
                  test_scores.shape[1],
              )
              * self.rating_max
          )
          test_scores = rescale(
              test_scores,
              self.rating_min,
              self.rating_max,
              user_min_scores,
              user_max_scores,
          )
  
      # remove items in the train set so recommended items are always novel
      if remove_seen:
          logger.info("Removing seen items")
          test_scores += self.user_affinity[user_ids, :] * -np.inf
  
      return test_scores
  
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 7 for calling the SARSingleNode obj's underlying member method code with example usage: obj.score(test, remove_seen) and returns: test_scores