Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Online ml River Reco RandomNormal

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Recommender_Systems, Baseline_Models
Last Updated 2026-02-08 16:00 GMT

Overview

Dummy recommender that predicts random values from a fitted normal distribution.

Description

Samples predictions from a normal distribution whose parameters (mean and variance) are fitted globally from observed ratings. Ignores user, item, and context information entirely. Serves as a sanity check baseline that any serious recommender should outperform.

Usage

Use as a baseline to verify that your recommendation model actually learns something useful. If your model doesn't beat this, something is wrong. Essential for establishing minimum performance thresholds.

Code Reference

Source Location

Signature

class RandomNormal(reco.base.Ranker):
    def __init__(self, seed=None):
        ...

    def learn_one(self, user, item, y, x=None):
        ...

    def predict_one(self, user, item, x=None):
        ...

Import

from river import reco

Usage 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)

# Prediction is random but from fitted distribution
pred = model.predict_one(user='Bob', item='Harry Potter')
print(f"Random prediction: {pred:.2f}")

# Check learned distribution
print(f"Mean: {model.mean.get():.2f}")
print(f"Variance: {model.variance.get():.2f}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment