class_docstr: An explicit feedback matrix factorization model. Uses a classic
  matrix factorization [1]_ approach, with latent vectors used
  to represent both users and items. Their dot product gives the
  predicted score for a user-item pair.
  
  The latent representation is given by
  :class:`spotlight.factorization.representations.BilinearNet`.
  
  .. [1] Koren, Yehuda, Robert Bell, and Chris Volinsky.
     "Matrix factorization techniques for recommender systems."
     Computer 42.8 (2009).
  
  Parameters
  ----------
  
  loss: string, optional
      One of 'regression', 'poisson', 'logistic'
      corresponding to losses from :class:`spotlight.losses`.
  embedding_dim: int, optional
      Number of embedding dimensions to use for users and items.
  n_iter: int, optional
      Number of iterations to run.
  batch_size: int, optional
      Minibatch size.
  l2: float, optional
      L2 loss penalty.
  learning_rate: float, optional
      Initial learning rate.
  optimizer_func: function, optional
      Function that takes in module parameters as the first argument and
      returns an instance of a PyTorch optimizer. Overrides l2 and learning
      rate if supplied. If no optimizer supplied, then use ADAM by default.
  use_cuda: boolean, optional
      Run the model on a GPU.
  representation: a representation module, optional
      If supplied, will override default settings and be used as the
      main network module in the model. Intended to be used as an escape
      hatch when you want to reuse the model's training functions but
      want full freedom to specify your network topology.
  sparse: boolean, optional
      Use sparse gradients for embedding layers.
  random_state: instance of numpy.random.RandomState, optional
      Random state to use when fitting.
class_docstr_tok: ["An","explicit","feedback","matrix","factorization","model",".","Uses","a","classic","matrix","factorization","[","1","]","_","approach",",","with","latent","vectors","used","to","represent","both","users","and","items",".","Their","dot","product","gives","the","predicted","score","for","a","user-item","pair",".","The","latent","representation","is","given","by",":","class",":","`","spotlight.factorization.representations.BilinearNet","`",".","..","[","1","]","Koren",",","Yehuda",",","Robert","Bell",",","and","Chris","Volinsky",".","``","Matrix","factorization","techniques","for","recommender","systems",".","''","Computer","42.8","(","2009",")",".","Parameters","--","--","--","--","--","loss",":","string",",","optional","One","of","'regression","'",",","'poisson","'",",","'logistic'","corresponding","to","losses","from",":","class",":","`","spotlight.losses","`",".","embedding_dim",":","int",",","optional","Number","of","embedding","dimensions","to","use","for","users","and","items",".","n_iter",":","int",",","optional","Number","of","iterations","to","run",".","batch_size",":","int",",","optional","Minibatch","size",".","l2",":","float",",","optional","L2","loss","penalty",".","learning_rate",":","float",",","optional","Initial","learning","rate",".","optimizer_func",":","function",",","optional","Function","that","takes","in","module","parameters","as","the","first","argument","and","returns","an","instance","of","a","PyTorch","optimizer",".","Overrides","l2","and","learning","rate","if","supplied",".","If","no","optimizer","supplied",",","then","use","ADAM","by","default",".","use_cuda",":","boolean",",","optional","Run","the","model","on","a","GPU",".","representation",":","a","representation","module",",","optional","If","supplied",",","will","override","default","settings","and","be","used","as","the","main","network","module","in","the","model",".","Intended","to","be","used","as","an","escape","hatch","when","you","want","to","reuse","the","model","'s","training","functions","but","want","full","freedom","to","specify","your","network","topology",".","sparse",":","boolean",",","optional","Use","sparse","gradients","for","embedding","layers",".","random_state",":","instance","of","numpy.random.RandomState",",","optional","Random","state","to","use","when","fitting","."]
docstr: Fit the model.
  
  When called repeatedly, model fitting will resume from
  the point at which training stopped in the previous fit
  call.
  
  Parameters
  ----------
  
  interactions: :class:`spotlight.interactions.Interactions`
      The input dataset. Must have ratings.
  
  verbose: bool
      Output additional information about current epoch and loss.
docstr_tok: ["Fit","the","model",".","When","called","repeatedly",",","model","fitting","will","resume","from","the","point","at","which","training","stopped","in","the","previous","fit","call",".","Parameters","--","--","--","--","--","interactions",":",":","class",":","`","spotlight.interactions.Interactions","`","The","input","dataset",".","Must","have","ratings",".","verbose",":","bool","Output","additional","information","about","current","epoch","and","loss","."]
code: def fit(self, interactions, verbose=False):
      """
      Fit the model.
  
      When called repeatedly, model fitting will resume from
      the point at which training stopped in the previous fit
      call.
  
      Parameters
      ----------
  
      interactions: :class:`spotlight.interactions.Interactions`
          The input dataset. Must have ratings.
  
      verbose: bool
          Output additional information about current epoch and loss.
      """
  
      user_ids = interactions.user_ids.astype(np.int64)
      item_ids = interactions.item_ids.astype(np.int64)
  
      if not self._initialized:
          self._initialize(interactions)
  
      self._check_input(user_ids, item_ids)
  
      for epoch_num in range(self._n_iter):
          users, items, ratings = shuffle(
              user_ids,
              item_ids,
              interactions.ratings,
              random_state=self._random_state,
          )
  
          user_ids_tensor = gpu(torch.from_numpy(users), self._use_cuda)
          item_ids_tensor = gpu(torch.from_numpy(items), self._use_cuda)
          ratings_tensor = gpu(
              torch.from_numpy(ratings), self._use_cuda
          )
  
          epoch_loss = 0.0
  
          for minibatch_num, (
              batch_user,
              batch_item,
              batch_ratings,
          ) in enumerate(
              minibatch(
                  user_ids_tensor,
                  item_ids_tensor,
                  ratings_tensor,
                  batch_size=self._batch_size,
              )
          ):
              predictions = self._net(batch_user, batch_item)
  
              if self._loss == "poisson":
                  predictions = torch.exp(predictions)
  
              self._optimizer.zero_grad()
  
              loss = self._loss_func(batch_ratings, predictions)
              epoch_loss += loss.item()
  
              loss.backward()
              self._optimizer.step()
  
          epoch_loss /= minibatch_num + 1
  
          if verbose:
              print("Epoch {}: loss {}".format(epoch_num, epoch_loss))
  
          if np.isnan(epoch_loss) or epoch_loss == 0.0:
              raise ValueError(
                  "Degenerate epoch loss: {}".format(epoch_loss)
              )
  
file_path: spotlight/spotlight/factorization/explicit.py
imports: import numpy
  import torch
  import torch.optim
  from spotlight.helpers import _repr_model
  from spotlight.factorization._components import _predict_process_ids
  from spotlight.factorization.representations import BilinearNet
  from spotlight.losses import poisson_loss, regression_loss, logistic_loss
  from spotlight.torch_utils import cpu, gpu, minibatch, set_seed, shuffle
label_desc: Use image node_id 6 for calling the ExplicitFactorizationModel obj's underlying member method code with example usage: obj.fit(interactions, verbose) without return types