class_docstr: Alternating Least Squares
  
  A Recommendation Model based off the algorithms described in the paper 'Collaborative
  Filtering for Implicit Feedback Datasets' with performance optimizations described in
  'Applications of the Conjugate Gradient Method for Implicit Feedback Collaborative
  Filtering.'
  
  Parameters
  ----------
  factors : int, optional
      The number of latent factors to compute
  regularization : float, optional
      The regularization factor to use
  alpha : float, optional
      The weight to give to positive examples.
  dtype : data-type, optional
      Specifies whether to use 16 bit or 32 bit floating point factors
  iterations : int, optional
      The number of ALS iterations to use when fitting data
  calculate_training_loss : bool, optional
      Whether to log out the training loss at each iteration
  random_state : int, RandomState or None, optional
      The random state for seeding the initial item and user factors.
      Default is None.
  
  Attributes
  ----------
  item_factors : ndarray
      Array of latent factors for each item in the training set
  user_factors : ndarray
      Array of latent factors for each user in the training set
docstr: Factorizes the user_items matrix.
  
  After calling this method, the members 'user_factors' and 'item_factors' will be
  initialized with a latent factor model of the input data.
  
  The user_items matrix does double duty here. It defines which items are liked by which
  users (P_ui in the original paper), as well as how much confidence we have that the user
  liked the item (C_ui.
  
  The negative items are implicitly defined: This code assumes that positive items in the
  user_items matrix means that the user liked the item. The negatives are left unset in this
  sparse matrix: the library will assume that means Piu = 0 and Ciu = 1 for all these items.
  Negative items can also be passed with a higher confidence value by passing a negative
  value, indicating that the user disliked the item.
  
  Parameters
  ----------
  user_items: csr_matrix
      Matrix of confidences for the liked items. This matrix should be a csr_matrix where
      the rows of the matrix are the user, the columns are the items liked by that user,
      and the value is the confidence that the user liked the item.
  show_progress : bool, optional
      Whether to show a progress bar during fitting
  callback: Callable, optional
      Callable function on each epoch with such arguments as epoch, elapsed time and progress
docstr_tok: ["Factorizes","the","user_items","matrix",".","After","calling","this","method",",","the","members","'user_factors","'","and","'item_factors","'","will","be","initialized","with","a","latent","factor","model","of","the","input","data",".","The","user_items","matrix","does","double","duty","here",".","It","defines","which","items","are","liked","by","which","users","(","P_ui","in","the","original","paper",")",",","as","well","as","how","much","confidence","we","have","that","the","user","liked","the","item","(","C_ui",".","The","negative","items","are","implicitly","defined",":","This","code","assumes","that","positive","items","in","the","user_items","matrix","means","that","the","user","liked","the","item",".","The","negatives","are","left","unset","in","this","sparse","matrix",":","the","library","will","assume","that","means","Piu","=","0","and","Ciu","=","1","for","all","these","items",".","Negative","items","can","also","be","passed","with","a","higher","confidence","value","by","passing","a","negative","value",",","indicating","that","the","user","disliked","the","item",".","Parameters","--","--","--","--","--","user_items",":","csr_matrix","Matrix","of","confidences","for","the","liked","items",".","This","matrix","should","be","a","csr_matrix","where","the","rows","of","the","matrix","are","the","user",",","the","columns","are","the","items","liked","by","that","user",",","and","the","value","is","the","confidence","that","the","user","liked","the","item",".","show_progress",":","bool",",","optional","Whether","to","show","a","progress","bar","during","fitting","callback",":","Callable",",","optional","Callable","function","on","each","epoch","with","such","arguments","as","epoch",",","elapsed","time","and","progress"]
code: def fit(self, user_items, show_progress=True, callback=None):
      """Factorizes the user_items matrix.
  
      After calling this method, the members 'user_factors' and 'item_factors' will be
      initialized with a latent factor model of the input data.
  
      The user_items matrix does double duty here. It defines which items are liked by which
      users (P_ui in the original paper), as well as how much confidence we have that the user
      liked the item (C_ui.
  
      The negative items are implicitly defined: This code assumes that positive items in the
      user_items matrix means that the user liked the item. The negatives are left unset in this
      sparse matrix: the library will assume that means Piu = 0 and Ciu = 1 for all these items.
      Negative items can also be passed with a higher confidence value by passing a negative
      value, indicating that the user disliked the item.
  
      Parameters
      ----------
      user_items: csr_matrix
          Matrix of confidences for the liked items. This matrix should be a csr_matrix where
          the rows of the matrix are the user, the columns are the items liked by that user,
          and the value is the confidence that the user liked the item.
      show_progress : bool, optional
          Whether to show a progress bar during fitting
      callback: Callable, optional
          Callable function on each epoch with such arguments as epoch, elapsed time and progress
      """
      # initialize the random state
      random_state = check_random_state(self.random_state)
  
      # TODO: allow passing in cupy arrays on gpu
      Cui = check_csr(user_items)
  
      if Cui.dtype != np.float32:
          Cui = Cui.astype(np.float32)
  
      s = time.time()
      Ciu = Cui.T.tocsr()
      log.debug("Calculated transpose in %.3fs", time.time() - s)
  
      items, users = Ciu.shape
  
      s = time.time()
  
      # Initialize the variables randomly if they haven't already been set
      if self.user_factors is None:
          self.user_factors = random_state.uniform(
              users,
              self.factors,
              low=-0.5 / self.factors,
              high=0.5 / self.factors,
          )
          self.user_factors = self.user_factors.astype(self.dtype)
  
      if self.item_factors is None:
          self.item_factors = random_state.uniform(
              items,
              self.factors,
              low=-0.5 / self.factors,
              high=0.5 / self.factors,
          )
          self.item_factors = self.item_factors.astype(self.dtype)
  
      log.debug("Initialized factors in %s", time.time() - s)
  
      # invalidate cached norms and squared factors
      self._item_norms = self._user_norms = None
      self._item_norms_host = self._user_norms_host = None
      self._YtY = self._XtX = None
  
      Ciu = implicit.gpu.CSRMatrix(Ciu)
      Cui = implicit.gpu.CSRMatrix(Cui)
      X = self.user_factors
      Y = self.item_factors
      loss = None
  
      _YtY = implicit.gpu.Matrix.zeros(self.factors, self.factors)
      _XtX = implicit.gpu.Matrix.zeros(self.factors, self.factors)
  
      log.debug("Running %i ALS iterations", self.iterations)
      with tqdm(
          total=self.iterations, disable=not show_progress
      ) as progress:
          for iteration in range(self.iterations):
              s = time.time()
              self.solver.calculate_yty(Y, _YtY, self.regularization)
              self.solver.least_squares(Cui, X, _YtY, Y, self.cg_steps)
  
              self.solver.calculate_yty(X, _XtX, self.regularization)
              self.solver.least_squares(Ciu, Y, _XtX, X, self.cg_steps)
              progress.update(1)
  
              if self.calculate_training_loss:
                  loss = self.solver.calculate_loss(
                      Cui, X, Y, self.regularization
                  )
                  progress.set_postfix({"loss": loss})
  
                  if not show_progress:
                      log.info("loss %.4f", loss)
  
              # Backward compatibility
              if not callback:
                  callback = self.fit_callback
              if callback:
                  callback(iteration, time.time() - s, loss)
  
      if self.calculate_training_loss:
          log.info("Final training loss %.4f", loss)
  
imports: import logging
  import time
  import numpy
  from tqdm.auto import tqdm
  import implicit.gpu
  from implicit.gpu.matrix_factorization_base import MatrixFactorizationBase, check_random_state
  from implicit.utils import check_csr
label_desc: Use image node_id 2 for calling the AlternatingLeastSquares obj's underlying member method code with example usage: obj.fit(user_items, show_progress, callback) without return types