Foundations to Frontier
Tests
D. Classical Machine Learning › D13 Recommender Systems

Factorization Machines

Factorization machines (Rendle, 2010) generalise matrix factorisation to arbitrary feature vectors. A prediction is a linear model plus every pairwise interaction between features, but instead of learning a separate weight for each pair, which is impossible when most pairs never co-occur in sparse data, each feature gets a k-dimensional factor vector, and the interaction weight of features i and j is the dot product ⟨vᵢ, vⱼ⟩. With one-hot user and item indicators an FM is exactly biased matrix factorisation; add user attributes, item attributes, context or history, and it becomes a single model that mixes collaborative and content signals, generalises to unseen combinations and softens cold start. A reformulation evaluates all pairwise interactions in O(nk) time per example, and the model trains by SGD, ALS or MCMC. FMs remain strong baselines for click-through prediction and inspired field-aware FMs and deep variants (DeepFM). This page covers the model, the O(nk) identity, its relation to MF and polynomial regression, training and regularisation, side features and cold start, and its extensions. In the exercises you implement an FM, verify the fast formula and its equivalence to MF; then you measure how side features help users with few ratings.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Every feature talks to every other feature

A prediction often depends on combinations: this user likes space films, this film suits weekends, engineers like documentaries. Learning a separate number for every combination is hopeless, because most combinations never appear in the data. Factorization machines give each feature, whether a user, a film, a genre, a user group or the time of day, a short vector, and measure how well any two features go together by how much their vectors point the same way. Combinations never seen before still get a sensible estimate.

Factorisation machines: every pair of features interacts through factor vectors
⟨user: new (no ratings), film: Mars Rovers⟩ = 0.00
⟨user: new (no ratings), user group: engineers⟩ = 0.00
⟨user: new (no ratings), genre: space⟩ = 0.00
⟨film: Mars Rovers, user group: engineers⟩ = 0.45
⟨film: Mars Rovers, genre: space⟩ = 0.45
⟨user group: engineers, genre: space⟩ = 0.33
score = w0 2.9 + linear 0.60 + pairwise 1.24 = 4.74 · O(nk) formula gives pairwise = 1.24
One-hot user and film alone make the FM exactly biased matrix factorisation (⟨v_user, v_film⟩). Add side features and a brand-new user with an all-zero factor still gets a sensible score from their group and the film's genre: the engineers-group vector points the same way as the space genre, so their interaction is positive. Every pair's weight comes from shared factor vectors, so pairs that never co-occurred in training still get estimates. A full second-order polynomial model would need a separate weight for each pair, and could not estimate them.
Why engineers care

Real prediction problems mix identifiers (user, item, asset) with attributes and context. FMs handle all of them in one sparse linear-plus-interactions model that trains quickly and copes with cold start. They are a standard baseline for click-through prediction and a useful bridge between classical models and deep recommenders such as DeepFM and two-tower networks.

📝 Quick check (Level 0)
0/3 answered
  1. 1. In an FM, the interaction weight of two features is…
  2. 2. An FM with only one-hot user and item features equals…
  3. 3. FMs can estimate interactions for feature pairs that…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The model and the fast formula by hand

Model (degree 2):

ŷ(x) = w₀ + Σᵢ wᵢxᵢ + Σᵢ<ⱼ ⟨vᵢ, vⱼ⟩ xᵢxⱼ,

with vᵢ ∈ ℝᵏ.

For x with features 0 and 2 active (one-hot), w₀ = 1, w = (0.1, 0.2, 0.3), v₀ = (1, 0) and v₂ = (0.5, 2): ŷ = 1 + 0.4 + ⟨v₀, v₂⟩ = 1 + 0.4 + 0.5 = 1.9.

Matrix factorisation as a special case. With x one-hot over users and items, only one pair is active: ŷ = w₀ + w_user + w_item + ⟨v_user, v_item⟩, which is μ + bᵤ + bᵢ + pᵤ·qᵢ.

The O(nk) identity:

Σᵢ<ⱼ ⟨vᵢ, vⱼ⟩xᵢxⱼ = ½ Σ_f [(Σᵢ vᵢ_f xᵢ)² − Σᵢ vᵢ_f² xᵢ²].

The right-hand side touches each non-zero feature once per factor: O(k · nnz(x)) instead of O(k · nnz²).

Parameters. 1 + n + nk: 1501 for n = 300 features and k = 4, against 44 850 separate pairwise weights for a full quadratic model.

The steps in plain English:

  1. Encode each example as a sparse vector: one-hot identifiers, categorical attributes, scaled numeric features, normalised multi-hot history.
  2. Initialise w₀ = mean target, w = 0 and small random V.
  3. Train by SGD (or ALS or MCMC) on squared or logistic loss, with L2 regularisation on w and V.
  4. Predict with the O(nk) formula; tune k and λ on validation data.
📝 Quick check (Level 1)
0/3 answered
  1. 1. The O(nk) identity avoids…
  2. 2. FM parameter count is…
  3. 3. With one-hot user and item, how many interaction terms are non-zero?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Why factorised interactions generalise

Polynomial regression fails on sparse data. A separate weight w_ij is learned only from examples where both i and j are active. For user × item pairs, the test pairs are by definition unseen, so their w_ij are never estimated. FMs share parameters: vᵢ is learned from every example containing i, so ⟨vᵢ, vⱼ⟩ is defined for any pair.

Gradients. ∂ŷ/∂vᵢ_f = xᵢ(Σⱼ vⱼ_f xⱼ) − vᵢ_f xᵢ². The bracketed sum is computed once per example, so an SGD step also costs O(k · nnz).

Side features and cold start. A new user has no learned user vector, but if group, location or device features are active, their vectors interact with item features to give a personalised prediction. As ratings accumulate, the user’s own vector takes over.

Exercise 1:

  • the O(nk) formula matched the explicit pairwise sum to 10⁻⁹;
  • an FM on one-hot (user, item) features, which is biased MF, reached held-out RMSE 0.470, against 0.940 for predicting the mean (the noise s.d. was 0.4).
# libFM, fastFM, or a few lines of PyTorch:
xv = X @ V                                                     # (batch, k)
y_hat = w0 + X @ w + 0.5 * (xv.pow(2) - (X.pow(2) @ V.pow(2))).sum(1)
🐍 Exercise 1: a factorisation machine
Implement FM prediction with the O(nk) formula, verify it against the explicit pairwise sum, train it by mini-batch SGD with L2 regularisation, and show that on one-hot (user, item) features it learns matrix factorisation.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Why can't polynomial regression predict an unseen user–item pair?
  2. 2. Side features help cold-start users because…
  3. 3. An SGD step for an FM costs about…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Expressiveness. Any symmetric positive semidefinite interaction matrix W can be written VVᵀ for large enough k, so an FM with enough factors can represent any such interaction pattern. Small k imposes a low-rank structure, which is what allows generalisation from sparse data. Higher-order FMs model triples, at greater cost.

Learning. Rendle’s libFM offers SGD, ALS (each parameter has a closed-form update with the others fixed, because ŷ is linear in each single parameter) and MCMC with Gibbs sampling, which integrates over the regularisation hyperparameters automatically.

Extensions.

  • Field-aware FMs (FFM, Juan et al., 2016) give each feature a separate vector per field of the other feature, and won several click-prediction competitions.
  • DeepFM and xDeepFM add neural components on the shared embeddings.
  • Attentional FMs weight interactions.

Interview questions.

  • When would you use an FM rather than MF? Whenever there are side features (user or item attributes, context, sequence features) or cold-start entities, or when the target is click-through prediction on sparse categorical data.
  • How do FMs relate to deep recommenders? The embedding-plus-dot-product interaction is the FM component inside DeepFM. Two-tower models are FMs restricted to user-side by item-side interactions, with neural encoders.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Field-aware FMs give each feature…
  2. 2. An FM's ALS update is closed-form because…
  3. 3. The FM component of DeepFM provides…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Do side features help new users?

History.

  • S. Rendle (2010) introduced factorisation machines, and libFM in 2012.
  • Y. Juan, Y. Zhuang, W.-S. Chin and C.-J. Lin (2016) introduced field-aware FMs.
  • H. Guo et al. (2017) introduced DeepFM.
  • FMs remain strong baselines for click-through prediction.

Exercise 2. 400 users and 150 items. A user’s taste vector is mainly their group’s (6 groups) plus individual noise, and an item’s is mainly its genre’s (5 genres). Users have geometrically distributed numbers of ratings. One rating per user was held out. Both models use k = 4 and the same training; MF uses one-hot user and item only, and the FM adds one-hot user group and item genre.

user’s training ratings test users MF (user, item only) FM with group and genre
0–2 58 0.877 0.694
3–10 132 0.664 0.533
11 or more 210 0.580 0.516
  • Side features helped most where data were scarcest: a 21% lower RMSE for users with 0–2 ratings, against 11% for users with more than 10. A cold user’s prediction came mostly from the group × genre interaction.
  • Even heavy users benefited, because group and genre vectors pool information that individual vectors must otherwise learn from noisy ratings.
  • The benefit depends on the side features carrying real signal. Here group and genre determined most of the taste; uninformative attributes would add parameters without help.
🐍 Exercise 2 (research): side features and cold start
Simulate users whose taste depends on their group and items whose factors depend on their genre; train an FM with and without group and genre features, and compare held-out RMSE by how many ratings each user has.

Factorisation machines in AI, robotics and aerospace

  • Click-through and engagement prediction for internal portals and tools, with user role, document type and time context.
  • Asset-condition prediction: asset ID × sensor-regime × environment interactions with sparse coverage, generalising to unseen combinations.
  • Cold-start personalisation: new operators or new aircraft tails predicted from attributes until their own data accumulate.

References

  1. S. Rendle (2010). “Factorization machines.” Proc. IEEE ICDM.
  2. S. Rendle (2012). “Factorization machines with libFM.” ACM Transactions on Intelligent Systems and Technology 3(3).
  3. Y. Juan, Y. Zhuang, W.-S. Chin, C.-J. Lin (2016). “Field-aware factorization machines for CTR prediction.” Proc. ACM RecSys.
  4. H. Guo, R. Tang, Y. Ye, Z. Li, X. He (2017). “DeepFM: a factorization-machine based neural network for CTR prediction.” Proc. IJCAI.