Skip to content
Back to skills

Recency Weighted Candidate Generation

ASecurity

Generates recommendation candidates by ranking a customer's purchase history by frequency and recency within a recent window.

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
developmentpythongo

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill recency-weighted-candidate-generation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Recency Weighted Candidate Generation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Recency Weighted Candidate Generation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-recency-weighted-candidate-generation/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-recency-weighted-candidate-generation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tabular-recency-weighted-candidate-generation
description: >
  Generates recommendation candidates by ranking a customer's purchase history by frequency and recency within a recent window.
---
# Recency-Weighted Candidate Generation

## Overview

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.

## Quick Start

```python
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]
```

## Workflow

1. Filter customer's transactions to recent activity window
2. Count purchases per item within that window
3. Sort by frequency (descending), then recency (descending) as tiebreaker
4. Deduplicate and take top-K as candidate recommendations
5. Pad remaining slots with popular items (see popularity-fallback skill)

## Key Decisions

- **Window size**: 7 days for fast-moving retail; 30+ for durable goods
- **Frequency vs recency**: Frequency first captures repeat-buy intent; recency first captures trend
- **When it works**: Strong for retail with high repurchase rates (groceries, fashion basics)
- **Combine**: Use as one candidate source alongside collaborative filtering and co-purchase

## References

- H&M Personalized Fashion Recommendations (Kaggle)
- Source: [recommend-items-purchased-together-0-021](https://www.kaggle.com/code/cdeotte/recommend-items-purchased-together-0-021)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.