Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ICWMF — Improved Context-aware Weighted Matrix Factorization for POI Recommendation

From-scratch reproduction of

Xu Zhou, Zhuoran Wang, Xuejie Liu, Yanheng Liu, Geng Sun. An improved context-aware weighted matrix factorization algorithm for point of interest recommendation in LBSN. Information Systems 122 (2024) 102366. https://doi.org/10.1016/j.is.2024.102366

on the Gowalla LBSN dataset.

Big Data Analytics — Final Project, Spring 2026 · Paper 1, Implementation questions.


Deliverable

notebooks/ICWMF_Gowalla.ipynb — the submission. It is organised into the four parts the brief asks for (Data preparation · Context modelling · ICWMF implementation · Evaluation and analysis) and ships with all outputs executed.

The algorithm itself lives in the icwmf/ package rather than inside notebook cells, so that the notebook reads as a report and the code stays testable and reviewable.

Quick start

python -m venv .venv
.venv\Scripts\activate            # Windows;  source .venv/bin/activate on POSIX
pip install -r requirements.txt

# The notebook downloads Gowalla itself on first run (~112 MB) into data/raw/.
jupyter lab notebooks/ICWMF_Gowalla.ipynb

Tests

python tests/test_icwmf.py          # or: python -m pytest tests -q

22 tests. Most are equivalence checks rather than smoke tests: each transcribes one of the paper's equations literally, with Python loops, on a small problem, and asserts the vectorised implementation agrees to floating-point tolerance — Eqs. (26)/(27) against dense weighted normal equations, Eq. (28) against its two explicit neighbour-set sums, Eq. (21) against a dense evaluation of all five terms, Eqs. (3)–(5) against a loop over Algorithm 1, Eqs. (17)–(20) element by element, and Eqs. (29)–(30) against a hand-worked example.

Layout

icwmf/
  config.py        hyper-parameters; Section 5.3 values + every paper-silent choice, documented
  data.py          Part 1  — download, filter, spatial sample, R / C, 80-20 split
  temporal.py      Part 2a — Algorithm 1, Eqs. (3)-(5), (22)   Ebbinghaus forgetting curve
  geo_location.py  Part 2b — Algorithm 2, Eqs. (6)-(8), (28)   proximity matrix T
  geo_user.py      Part 2b — Algorithm 3, Eqs. (9)-(16)        DBSCAN, centres, power law
  social.py        Part 2c — Algorithm 4, Eqs. (17)-(20), (23) social preference, D
  model.py         Part 3  — Algorithm 5, Eqs. (21)-(28)       ALS solver
  baselines.py             — Eq. (2) plain WMF, MostPopular
  evaluate.py      Part 4  — Eqs. (29)-(30)                    Precision@n / Recall@n
  plots.py                 — figure styling and chart helpers
  cache.py                 — on-disk memoisation
  utils.py                 — haversine, sparse helpers
tests/test_icwmf.py        — equivalence tests against literal transcriptions of the equations
notebooks/                 — the deliverable
data/raw/                  — Gowalla downloads (git-ignored)
cache/                     — memoised fits (git-ignored)

Implementation notes

Written from scratch. No matrix-factorization or recommender library is used. scikit-learn appears only for the two helpers the brief explicitly permits: NearestNeighbors (Algorithm 2) and DBSCAN (Algorithm 3).

Efficiency. Eq. (21) is written over dense N × M matrices — ~6 × 10¹⁴ flops per ALS sweep as stated. Two reductions make it tractable: W = 1 on every unvisited POI, so V^T W_u V = V^T V + Σ_{l visited}(W−1) V_l^T V_l with V^T V shared across users; and D is genuinely sparse. Cost per sweep becomes O((nnz(C)+nnz(D))K² + (N+M)K³), ≈ 30–60 s at K = 300.

Headline results. Under the evaluation protocol the paper's own metric ratio implies (re-visits count as hits), ICWMF reaches Precision@10 = 0.132 / Recall@10 = 0.205 against the paper's 0.26 / 0.13, beating plain WMF at every cut-off and MostPopular by 2.4×. Three findings the notebook documents rather than smooths over: K = 300 overfits badly (under a strict new-POI protocol, every factorisation model loses to a popularity list); the location regularisation term is numerically inert at the published λ_T and diverges if raised, because Eq. (27) omits the λ_T·I that makes the update a contraction; and the implicit-feedback term helps, but as shrinkage rather than by the mechanism the paper describes.

Sampling. The paper's Table 1 subset (2,150 users) cannot be produced from the SNAP dump by the two filtering rules it states, so we take a documented spatial sample — the Austin, TX bounding box, Gowalla's home city and the densest region of the dataset — and then apply the paper's rules to the fixed point. The result matches Table 1's density (7.5 × 10⁻³ vs 7.4 × 10⁻³), which is the property that governs the difficulty of the task.

Every point where the paper is silent is marked with a "Design decision" note in the notebook and documented in icwmf/config.py.

Data

Downloaded automatically from SNAP on first run:

File Size
loc-gowalla_totalCheckins.txt.gz 105 MB — 6,442,892 check-ins, 107,092 users, 1,280,969 POIs
loc-gowalla_edges.txt.gz 6 MB — 950,327 friendships

About

From-scratch reproduction of ICWMF (Zhou et al. 2024) — context-aware weighted matrix factorization for POI recommendation on the Gowalla LBSN dataset.

Resources

Stars

13 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages