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: Co-occurrence matrix.
  
  The co-occurrence matrix is defined as :math:`C = U^T * U`
  
  where U is the user_affinity matrix with 1's as values (instead of ratings).
  
  Args:
      df (pandas.DataFrame): DataFrame of users and items
  
  Returns:
      numpy.ndarray: Co-occurrence matrix
docstr_tok: ["Co-occurrence","matrix",".","The","co-occurrence","matrix","is","defined","as",":","math",":","`","C","=","U^T","*","U","`","where","U","is","the","user_affinity","matrix","with","1","'s","as","values","(","instead","of","ratings",")",".","Args",":","df","(","pandas.DataFrame",")",":","DataFrame","of","users","and","items","Returns",":","numpy.ndarray",":","Co-occurrence","matrix"]
code: def compute_cooccurrence_matrix(self, df):
      """Co-occurrence matrix.
  
      The co-occurrence matrix is defined as :math:`C = U^T * U`
  
      where U is the user_affinity matrix with 1's as values (instead of ratings).
  
      Args:
          df (pandas.DataFrame): DataFrame of users and items
  
      Returns:
          numpy.ndarray: Co-occurrence matrix
      """
      user_item_hits = sparse.coo_matrix(
          (
              np.repeat(1, df.shape[0]),
              (df[self.col_user_id], df[self.col_item_id]),
          ),
          shape=(self.n_users, self.n_items),
      ).tocsr()
  
      item_cooccurrence = user_item_hits.transpose().dot(user_item_hits)
      item_cooccurrence = item_cooccurrence.multiply(
          item_cooccurrence >= self.threshold
      )
  
      return item_cooccurrence.astype(df[self.col_rating].dtype)
  
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 4 for calling the SARSingleNode obj's underlying member method code with example usage: obj.compute_cooccurrence_matrix(df) and returns: item_cooccurrence