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: Initialize model parameters
  
  Args:
      col_user (str): user column name
      col_item (str): item column name
      col_rating (str): rating column name
      col_timestamp (str): timestamp column name
      col_prediction (str): prediction column name
      similarity_type (str): ['cooccurrence', 'cosine', 'inclusion index', 'jaccard',
        'lexicographers mutual information', 'lift', 'mutual information'] option for
        computing item-item similarity
      time_decay_coefficient (float): number of days till ratings are decayed by 1/2
      time_now (int | None): current time for time decay calculation
      timedecay_formula (bool): flag to apply time decay
      threshold (int): item-item co-occurrences below this threshold will be removed
      normalize (bool): option for normalizing predictions to scale of original ratings
docstr_tok: ["Initialize","model","parameters","Args",":","col_user","(","str",")",":","user","column","name","col_item","(","str",")",":","item","column","name","col_rating","(","str",")",":","rating","column","name","col_timestamp","(","str",")",":","timestamp","column","name","col_prediction","(","str",")",":","prediction","column","name","similarity_type","(","str",")",":","[","'cooccurrence","'",",","'cosine","'",",","'inclusion","index","'",",","'jaccard","'",",","'lexicographers","mutual","information","'",",","'lift","'",",","'mutual","information","'","]","option","for","computing","item-item","similarity","time_decay_coefficient","(","float",")",":","number","of","days","till","ratings","are","decayed","by","1\/2","time_now","(","int","|","None",")",":","current","time","for","time","decay","calculation","timedecay_formula","(","bool",")",":","flag","to","apply","time","decay","threshold","(","int",")",":","item-item","co-occurrences","below","this","threshold","will","be","removed","normalize","(","bool",")",":","option","for","normalizing","predictions","to","scale","of","original","ratings"]
code: def __init__(
      self,
      col_user=constants.DEFAULT_USER_COL,
      col_item=constants.DEFAULT_ITEM_COL,
      col_rating=constants.DEFAULT_RATING_COL,
      col_timestamp=constants.DEFAULT_TIMESTAMP_COL,
      col_prediction=constants.DEFAULT_PREDICTION_COL,
      similarity_type=SIM_JACCARD,
      time_decay_coefficient=30,
      time_now=None,
      timedecay_formula=False,
      threshold=1,
      normalize=False,
  ):
      """Initialize model parameters
  
      Args:
          col_user (str): user column name
          col_item (str): item column name
          col_rating (str): rating column name
          col_timestamp (str): timestamp column name
          col_prediction (str): prediction column name
          similarity_type (str): ['cooccurrence', 'cosine', 'inclusion index', 'jaccard',
            'lexicographers mutual information', 'lift', 'mutual information'] option for
            computing item-item similarity
          time_decay_coefficient (float): number of days till ratings are decayed by 1/2
          time_now (int | None): current time for time decay calculation
          timedecay_formula (bool): flag to apply time decay
          threshold (int): item-item co-occurrences below this threshold will be removed
          normalize (bool): option for normalizing predictions to scale of original ratings
      """
      self.col_rating = col_rating
      self.col_item = col_item
      self.col_user = col_user
      self.col_timestamp = col_timestamp
      self.col_prediction = col_prediction
  
      available_similarity_types = [
          SIM_COOCCUR,
          SIM_COSINE,
          SIM_INCLUSION_INDEX,
          SIM_JACCARD,
          SIM_LIFT,
          SIM_MUTUAL_INFORMATION,
          SIM_LEXICOGRAPHERS_MUTUAL_INFORMATION,
      ]
      if similarity_type not in available_similarity_types:
          raise ValueError(
              'Similarity type must be one of ["'
              + '" | "'.join(available_similarity_types)
              + '"]'
          )
      self.similarity_type = similarity_type
      self.time_decay_half_life = (
          time_decay_coefficient * 24 * 60 * 60
      )  # convert to seconds
      self.time_decay_flag = timedecay_formula
      self.time_now = time_now
      self.threshold = threshold
      self.user_affinity = None
      self.item_similarity = None
      self.item_frequencies = None
      self.user_frequencies = None
  
      # threshold - items below this number get set to zero in co-occurrence counts
      if self.threshold <= 0:
          raise ValueError("Threshold cannot be < 1")
  
      # set flag to capture unity-rating user-affinity matrix for scaling scores
      self.normalize = normalize
      self.col_unity_rating = "_unity_rating"
      self.unity_user_affinity = None
  
      # column for mapping user / item ids to internal indices
      self.col_item_id = "_indexed_items"
      self.col_user_id = "_indexed_users"
  
      # obtain all the users and items from both training and test data
      self.n_users = None
      self.n_items = None
  
      # The min and max of the rating scale, obtained from the training data.
      self.rating_min = None
      self.rating_max = None
  
      # mapping for item to matrix element
      self.user2index = None
      self.item2index = None
  
      # the opposite of the above maps - map array index to actual string ID
      self.index2item = None
      self.index2user = None
  
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 1 to create a new SARSingleNode object  with example: obj = SARSingleNode(col_user, col_item, col_rating, col_timestamp, col_prediction, similarity_type, time_decay_coefficient, time_now, timedecay_formula, threshold, normalize)