skills/tabular/implicit-als-collaborative-filtering/SKILL.md
Alternating Least Squares matrix factorization on sparse user-item interaction matrices for implicit feedback recommendations.
npx skillsauth add wenmin-wu/ds-skills tabular-implicit-als-collaborative-filteringInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For implicit feedback (purchases, clicks — no ratings), factorize the sparse user-item interaction matrix into low-rank latent factors using ALS. The implicit library provides a GPU-accelerated implementation. Recommendations come from dot-product similarity between user and item factor vectors.
import implicit
import numpy as np
from scipy.sparse import coo_matrix
def build_interaction_matrix(df, user_col, item_col):
users = df[user_col].astype("category")
items = df[item_col].astype("category")
data = np.ones(len(df))
return coo_matrix((data, (users.cat.codes, items.cat.codes)))
coo = build_interaction_matrix(transactions, "customer_id", "article_id")
model = implicit.als.AlternatingLeastSquares(
factors=100, iterations=15, regularization=0.01
)
model.fit(coo.tocsr())
# Recommend for a user
ids, scores = model.recommend(user_id, coo.tocsr()[user_id], N=12)
model.recommendimplicit supports GPU; 10x faster for large matricesdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF