What does Completing Preferences from Sparse Purchases conclude, in numbers, about “Cold Start: Catching New Customers and New Products with Means and Category Priors”?

Answer: Chapter 6 treats cold start: a new customer with eight records reaches an error of 0.2434 by folding in with shrinkage toward the category prior.

Scope of the numbers: Marked boxes separate published evidence, runnable Python calculations (23 programs), classical sources and the author's hypotheses.

中文版

Data table

The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 0.2434

20 new customers; RMSE on their unobserved products
kglobalproductsegmentfold-in
00.84020.72830.48350.4835
10.83740.72940.48320.4313
20.85220.74230.48680.4207
40.85400.74440.48870.3586
80.86630.74400.48180.2434
Show the full program
# Chapter 6. p61: a new customer with k purchases.
# Model: 60 established customers x 24 products in 4 shelf categories;
# customers fall in 4 segments by first-purchase category, and their
# rank-3 tastes scatter around a segment mean (illustrative). Product
# factors come from ALS on the established customers (40 percent
# observed). For 20 new customers we predict every product from k
# observed scores: global mean; product means; segment prior; and a
# ridge fold-in shrunk toward the segment prior (lambda 2).
import math
import random


def dot(a, b):
    return math.fsum(x * y for x, y in zip(a, b))


def solve(A, b):
    # Gaussian elimination with partial pivoting for a small system
    n = len(b)
    M = [list(A[i]) + [b[i]] for i in range(n)]
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(M[i][k]))
        M[k], M[p] = M[p], M[k]
        for i in range(k + 1, n):
            f = M[i][k] / M[k][k]
            M[i] = [M[i][j] - f * M[k][j] for j in range(n + 1)]
    x = [0.0] * n
    for i in range(n - 1, -1, -1):
        s = math.fsum(M[i][j] * x[j] for j in range(i + 1, n))
        x[i] = (M[i][n] - s) / M[i][i]
    return x


def update(trip, F, r, lam, prior=None):
    # weighted ridge step for one row: minimise
    # sum w (y - f.x)^2 + lam |x - prior|^2 over x
    pr = prior if prior is not None else [0.0] * r
    A = [[math.fsum(w * F[j][a] * F[j][b] for j, _, w in trip)
          + (lam if a == b else 0.0) for b in range(r)]
         for a in range(r)]
    y = [math.fsum(w * F[j][a] * v for j, v, w in trip) + lam * pr[a]
         for a in range(r)]
    return solve(A, y)


def als(nu, ni, obs, r, lam, iters, seed, V=None, trace=None):
    # alternating least squares on (u, i, value, weight) tuples
    rng = random.Random(seed)
    if V is None:
        V = [[rng.gauss(0.0, 1.0) for _ in range(r)] for _ in range(ni)]
    bu = [[] for _ in range(nu)]
    bi = [[] for _ in range(ni)]
    for u, i, x, w in obs:
        bu[u].append((i, x, w))
        bi[i].append((u, x, w))
    U = None
    for t in range(iters):
        U = [update(bu[u], V, r, lam) for u in range(nu)]
        V = [update(bi[i], U, r, lam) for i in range(ni)]
        if trace is not None:
            trace.append((t + 1, U, V))
    return U, V


def factors(n, r, rng):
    return [[rng.gauss(0.0, 1.0) for _ in range(r)] for _ in range(n)]


def product(A, B):
    return [[dot(a, b) for b in B] for a in A]


def mask(nu, ni, p, rng):
    return [(u, i) for u in range(nu) for i in range(ni)
            if rng.random() < p]

def store(rng, nu=60, ni=24, r=3, segs=4):
    # customer segment = first purchase category (store data);
    # product category = shelf; latent factors share a segment mean
    cen = [[rng.gauss(0, 1) for _ in range(r)] for _ in range(segs)]
    cat = [[rng.gauss(0, 1) for _ in range(r)] for _ in range(segs)]
    sg = [u % segs for u in range(nu)]
    ct = [i % segs for i in range(ni)]
    A = [[c + rng.gauss(0, 0.5) for c in cen[sg[u]]] for u in range(nu)]
    B = [[c + rng.gauss(0, 0.5) for c in cat[ct[i]]] for i in range(ni)]
    T = [[3.0 + 0.4 * dot(a, b) for b in B] for a in A]
    return T, sg, ct


rng = random.Random(20261113)
T, sg, ct = store(rng, nu=80)
nu, ni, r = 60, 24, 3
seen = mask(nu, ni, 0.4, rng)
g = math.fsum(T[u][i] for u, i in seen) / len(seen)
obs = [(u, i, T[u][i] - g, 1.0) for u, i in seen]
U, V = als(nu, ni, obs, r, 1.0, 60, 6)
im = []
for i in range(ni):
    xs = [T[u][j] for u, j in seen if j == i]
    im.append(math.fsum(xs) / len(xs))
pri = []
for s in range(4):
    us = [U[u] for u in range(nu) if sg[u] == s]
    pri.append([math.fsum(x[k] for x in us) / len(us) for k in range(r)])
new = list(range(60, 80))
print("20 new customers; RMSE on their unobserved products")
print("   k   global   product   segment   fold-in")
for k in (0, 1, 2, 4, 8):
    e = {"g": [], "p": [], "s": [], "f": []}
    for u in new:
        order = list(range(ni))
        random.Random(1000 + u).shuffle(order)
        known, rest = order[:k], order[k:]
        pr = pri[sg[u]]
        trip = [(i, T[u][i] - g, 1.0) for i in known]
        uf = update(trip, V, r, 2.0, prior=pr)
        for i in rest:
            e["g"].append((g - T[u][i]) ** 2)
            e["p"].append((im[i] - T[u][i]) ** 2)
            e["s"].append((g + dot(pr, V[i]) - T[u][i]) ** 2)
            e["f"].append((g + dot(uf, V[i]) - T[u][i]) ** 2)
    out = [math.sqrt(math.fsum(e[x]) / len(e[x])) for x in "gpsf"]
    print("  {:2d}   {:.4f}   {:.4f}    {:.4f}    {:.4f}".format(k, *out))

Single source and citation

Fan, Y. (2026). Low-Rank Matrix Completion and Alternating Least Squares: Inferring Unstated Preferences from Sparse Purchase Records (Version 1.0.0), Chapter 6: Cold Start: Catching New Customers and New Products with Means and Category Priors. 5D Library. DOI pending

DOI pending · monograph page goes live after publication · 5DL-B-328 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026328,
  author    = {Fan, Yafu},
  title     = {Low-Rank Matrix Completion and Alternating Least Squares: Inferring Unstated Preferences from Sparse Purchase Records},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

Other chapter answers in this book