skills/tabular/co-purchase-item-pairing/SKILL.md
Recommends items frequently purchased together with a customer's recent items using pre-computed pair dictionaries.
npx skillsauth add wenmin-wu/ds-skills tabular-co-purchase-item-pairingInstall 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 each item, pre-compute the most frequently co-purchased item (bought by the same customer in the same session or time window). At inference, map each of a customer's recent purchases to its paired item and add those as recommendations. This captures "bought together" patterns that collaborative filtering may miss.
import pandas as pd
from collections import Counter
def build_pair_dict(transactions, time_window_days=7):
"""Find most common co-purchase for each item."""
df = transactions.sort_values(["customer_id", "t_dat"])
df["next_item"] = df.groupby("customer_id")["article_id"].shift(-1)
df["day_diff"] = df.groupby("customer_id")["t_dat"].diff(-1).dt.days.abs()
pairs = df[df["day_diff"] <= time_window_days]
pair_counts = pairs.groupby("article_id")["next_item"].apply(
lambda x: Counter(x).most_common(1)[0][0]
)
return pair_counts.to_dict()
pairs = build_pair_dict(transactions)
# At inference: map customer's recent items to co-purchased items
recs = [pairs.get(item) for item in customer_history if item in pairs]
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