skills/tabular/recency-weighted-candidate-generation/SKILL.md
Generates recommendation candidates by ranking a customer's purchase history by frequency and recency within a recent window.
npx skillsauth add wenmin-wu/ds-skills tabular-recency-weighted-candidate-generationInstall 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 systems, generate candidates from a customer's own purchase history, weighted by how recently and frequently they bought each item. Filter to a recent time window (e.g., last 7 days of activity), count purchases per item, sort by count then date, and deduplicate. This "repurchase" signal is surprisingly strong in retail.
import pandas as pd
def generate_candidates(transactions, customer_id, days=7):
cust = transactions[transactions["customer_id"] == customer_id]
cutoff = cust["t_dat"].max() - pd.Timedelta(days=days)
recent = cust[cust["t_dat"] >= cutoff]
counts = recent.groupby("article_id").agg(
ct=("t_dat", "count"),
last_date=("t_dat", "max")
).reset_index()
counts = counts.sort_values(["ct", "last_date"], ascending=False)
return counts["article_id"].tolist()[:12]
data-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