Quick Reference · collective matrix factorization · hybrid recommenders

cmfrec cheat sheet

Factorize an interactions matrix X ≈ A·Bᵀ — and here's the twist — jointly factorize user side-info U ≈ A·Cᵀ and item side-info I ≈ B·Dᵀ sharing the same factors. That shared structure is what turns plain collaborative filtering into a hybrid model that can recommend for brand-new users and items (cold-start).

data & install model classes fit / train predict / recommend hyperparameters gotcha most common

Distilled & cross-checked across: cmfrec.readthedocs.io · github.com/david-cortes/cmfrec · CRAN cmfrec manual · Cortes 2018 (arXiv:1809.00366) · Singh & Gordon 2008 · Hu, Koren & Volinsky 2008

The pipeline — from a ratings table to ranked recommendations
Your data X  UserId,ItemId,Rating U  user attributes I  item attributes DataFrame · COO · dense Model CMF(...) CMF_implicit(...) k, lambda_, method Learned factors A · B · C · D + user / item biases + glob_mean .fit(X, U, I) Serve .predict(user, item) .topN(user, n) .topN_warm / _cold / _new ranked item lists + scores build fit query cold-start · new user/item enters via U or I side-info, no history needed INPUT OUTPUT
01Install & Importonce per env
02Pick a Model7 classes, one idea
03Prepare Your Datashapes & missing
04Fit the Modellearn A,B,C,D
05Predict & Scorerating for a pair
06Top-N Recommendationsranked lists
07Latent Factorsembed new rows
08Core Hyperparameterstune these first
09Implicit-Feedback KnobsCMF_implicit
10Shared vs Split Factorsthe collective trick
11Advanced Optionsreshape the objective
12Impute & Pipelinesbeyond recsys
13Production & Servingship it lean
14Gotchasread before you fit
warm · cold · newthe naming key

How the pieces fit

Four ways of looking at the same model. The first is the whole thesis of the library; the rest unpack the factor layout, the prediction modes, and why explicit and implicit are different objectives.

Coupled factorization

X, U and I are factorized together. A is shared by X&U; B is shared by X&I — that shared spine is the whole point.

X A Bᵀ users × items interactions U A Cᵀ users × attrs ← shares A I B Dᵀ items × attrs ← shares B

Factor layout

Each matrix is a band of columns. The green k block is shared everywhere; coloured blocks are private to one factorization.

A k_user k (shared) k_main B k_item k (shared) k_main C k_user k (shared) D k_item k (shared) green columns tie the matrices together; violet / amber columns stay private.

existing · warm · cold · new

Which method to reach for depends on what you have: stored history, fresh ratings, user attributes, or item attributes.

existing in training data predict() · topN() uses stored A row warm new ratings X *_warm(X_col, X_val) re-solves A from X cold user attributes U *_cold(U=...) A from U · C, no X new item attributes I *_new(I=...) B from I · D

explicit vs implicit loss

Explicit fits error on the cells you observed and ignores blanks. Implicit treats every cell as 0/1 and weights it by confidence.

CMF (explicit) CMF_implicit 4 2 5 3 loss on rated cells only blanks are ignored 1 0 1 0 0 1 0 0 0 0 1 0 every cell counts weight = 1 + alpha·value Same data, opposite assumption about the blanks — that choice is why the two models exist.

Worth memorizing

CMF ≠ CMF_implicitexplicit ratings vs weighted-binary clicks
lambda_ is absolutenot per-entry — tune far wider than other libs
warm ≠ coldwarm = new X ratings; cold = new U attrs only
shared A & Bside info couples to X → cold-start works
als vs lbfgsals = fast; lbfgs = binary side info + sigmoid
k_user/k_item/k_mainprivate factors bolted onto the shared k
.fit mutates inputreindexes in place — df.copy() first
topN is a full scanuse hnsw / Milvus on A·B for big catalogs