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 FunkMF

From Leeroopedia
Revision as of 16:10, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Online_ml_River_Reco_FunkMF.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

Pure matrix factorization without biases using latent factor dot products.

Description

Implements the original Funk SVD algorithm: ŷ = <vu, vi>, modeling ratings purely through latent factor interactions. Simpler than BiasedMF but can still capture complex user-item relationships. Named after Simon Funk who popularized this approach during the Netflix Prize competition.

Usage

Use when bias terms are not needed or when data is already centered. Suitable for implicit feedback scenarios or when you want the simplest latent factor model. Good starting point before adding complexity.

Code Reference

Source Location

Signature

class FunkMF(reco.base.Ranker):
    def __init__(
        self,
        n_factors=10,
        optimizer: optim.base.Optimizer | None = None,
        loss: optim.losses.Loss | None = None,
        l2=0.0,
        initializer: optim.initializers.Initializer | None = None,
        clip_gradient=1e12,
        seed=None,
    ):
        ...

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

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

Import

from river import reco

Usage Examples

from river import optim, 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.FunkMF(
    n_factors=10,
    optimizer=optim.SGD(0.1),
    initializer=optim.initializers.Normal(mu=0., sigma=0.1, seed=11),
)

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

pred = model.predict_one(user='Bob', item='Harry Potter')
print(f"Predicted rating: {pred:.2f}")

Related Pages

Page Connections

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