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

    DefaultNone

    Random number generation seed. Set this for reproducibility.

Attributes

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'ID'
  • item'ID'
  • y'Reward'
  • x'dict | None' — defaults to None

predict_one

Predicts the target value of a set of features x.

Parameters

  • user'ID'
  • item'ID'
  • x'dict | None' — defaults to None

Returns

Reward: The predicted preference from the user for the item.

rank

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

Parameters

  • user'ID'
  • items'set[ID]'
  • x'dict | None' — defaults to None