class_docstr: Baseline for recommender systems.
  
  A first-order approximation of the bias involved in target. The model equation is defined as:
  
  $$\hat{y}(x) = \bar{y} + bu_{u} + bi_{i}$$
  
  Where $bu_{u}$ and $bi_{i}$ are respectively the user and item biases.
  
  This model expects a dict input with a `user` and an `item` entries without any type constraint
  on their values (i.e. can be strings or numbers). Other entries are ignored.
  
  Parameters
  ----------
  optimizer
      The sequential optimizer used for updating the weights.
  loss
      The loss function to optimize for.
  l2
      regularization amount used to push weights towards 0.
  initializer
      Weights initialization scheme.
  clip_gradient
      Clips the absolute value of each gradient value.
  seed
      Random number generation seed. Set this for reproducibility.
  
  Attributes
  ----------
  global_mean : stats.Mean
      The target arithmetic mean.
  u_biases : collections.defaultdict
      The user bias weights.
  i_biases : collections.defaultdict
      The item bias weights.
  u_optimizer : optim.base.Optimizer
      The sequential optimizer used for updating the user bias weights.
  i_optimizer : optim.base.Optimizer
      The sequential optimizer used for updating the item bias weights.
  
  Examples
  --------
  
  >>> from river import optim
  >>> from river import reco
  
  >>> dataset = (
  ...     ({'user': 'Alice', 'item': 'Superman'}, 8),
  ...     ({'user': 'Alice', 'item': 'Terminator'}, 9),
  ...     ({'user': 'Alice', 'item': 'Star Wars'}, 8),
  ...     ({'user': 'Alice', 'item': 'Notting Hill'}, 2),
  ...     ({'user': 'Alice', 'item': 'Harry Potter'}, 5),
  ...     ({'user': 'Bob', 'item': 'Superman'}, 8),
  ...     ({'user': 'Bob', 'item': 'Terminator'}, 9),
  ...     ({'user': 'Bob', 'item': 'Star Wars'}, 8),
  ...     ({'user': 'Bob', 'item': 'Notting Hill'}, 2)
  ... )
  
  >>> model = reco.Baseline(optimizer=optim.SGD(0.005))
  
  >>> for x, y in dataset:
  ...     model.learn_one(**x, y=y)
  
  >>> model.predict_one(user='Bob', item='Harry Potter')
  6.538120
  
  References
  ----------
  [^1]: [Matrix factorization techniques for recommender systems](https://datajobs.com/data-science-repo/Recommender-Systems-[Netflix].pdf)
code: def learn_one(self, user, item, y, x=None):
      # Update the global mean
      self.global_mean.update(y)
  
      # Calculate the gradient of the loss with respect to the prediction
      g_loss = self.loss.gradient(y, self.predict_one(user, item))
  
      # Clamp the gradient to avoid numerical instability
      g_loss = utils.math.clamp(
          g_loss,
          minimum=-self.clip_gradient,
          maximum=self.clip_gradient,
      )
  
      # Calculate bias gradients
      u_grad_bias = {user: g_loss + self.l2 * self.u_biases[user]}
      i_grad_bias = {item: g_loss + self.l2 * self.i_biases[item]}
  
      # Update biases
      self.u_biases = self.u_optimizer.step(self.u_biases, u_grad_bias)
      self.i_biases = self.i_optimizer.step(self.i_biases, i_grad_bias)
  
file_path: river/river/reco/baseline.py
imports: from __future__ import annotations
  import collections
  import copy
  from river import optim, reco, stats, utils
label_desc: Use image node_id 3 for calling the Baseline obj's underlying member method code with example usage: obj.learn_one(user, item, y, x) without return types