Skip to content

RandomNormal

Predicts random values sampled from a normal distribution.

The parameters of the normal distribution are fitted with running statistics. They parameters are independent of the user, the item, or the context, and are instead fitted globally. This recommender therefore acts as a dummy model that any serious model should easily outperform.

Parameters

  • seed – defaults to None

    Random number generation seed. Set this for reproducibility.

Attributes

  • mean

    stats.Mean

  • variance

    stats.Var

Examples

>>> 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.RandomNormal(seed=42)

>>> for x, y in dataset:
...     _ = model.learn_one(**x, y=y)

>>> model.predict_one(user='Bob', item='Harry Potter')
6.147299621751425

Methods

learn_one

Fits a user-item pair and a real-valued target y.

Parameters

  • user (Union[str, int])
  • item (Union[str, int])
  • y (Union[numbers.Number, bool])
  • x (dict) – defaults to None
predict_one

Predicts the target value of a set of features x.

Parameters

  • user (Union[str, int])
  • item (Union[str, int])
  • x (dict) – defaults to None

Returns

typing.Union[numbers.Number, bool]: The predicted preference from the user for the item.

rank

Rank models by decreasing order of preference for a given user.

Parameters

  • user (Union[str, int])
  • items (Set[Union[str, int]])
  • x (dict) – defaults to None