skills/tabular/multi-source-candidate-fusion/SKILL.md
Fuse recommendation candidates from user history, multiple co-visitation matrices, and global popularity in a priority-ordered cascade
npx skillsauth add wenmin-wu/ds-skills tabular-multi-source-candidate-fusionInstall 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 recommendation tasks requiring top-K predictions, fuse candidates from multiple signal sources in priority order: (1) user's own history (recency-deduped), (2) co-visitation expansions from multiple matrices (clicks, carts/orders, buy2buy), (3) global popularity fallback. Each source fills remaining slots until K is reached. Ensures every user gets exactly K predictions regardless of history length.
import itertools
from collections import Counter
def fuse_candidates(session_aids, session_types, covisit_clicks,
covisit_buys, covisit_buy2buy, top_popular, k=20):
"""Fuse candidates from multiple sources with priority fallback.
Args:
session_aids: user's session item IDs (chronological)
session_types: interaction types per event
covisit_*: dict mapping aid -> list of top co-visited aids
top_popular: list of globally popular item IDs
k: number of candidates to return
"""
# Priority 1: user history (recent first, deduplicated)
unique_aids = list(dict.fromkeys(session_aids[::-1]))
if len(unique_aids) >= k:
return unique_aids[:k]
# Priority 2: co-visitation expansion
buy_aids = [a for a, t in zip(session_aids, session_types) if t in [1,2]]
unique_buys = list(dict.fromkeys(buy_aids[::-1]))
expanded = list(itertools.chain(
*[covisit_buys.get(a, []) for a in unique_aids],
*[covisit_buy2buy.get(a, []) for a in unique_buys]
))
top_expanded = [a for a, _ in Counter(expanded).most_common(k)
if a not in set(unique_aids)]
result = unique_aids + top_expanded[:k - len(unique_aids)]
# Priority 3: global popularity fallback
if len(result) < k:
result += [a for a in top_popular if a not in set(result)][:k - len(result)]
return result[:k]
dict.fromkeys(aids[::-1]) keeps most recent occurrence of each itemdata-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