Brief
Recommendation systems are everywhere, and the simplest good one is "find things like this". You'll build that for recipes. Pick a recipe you like and the tool returns the ten recipes that use the most similar ingredients.
The data is "Food.com Recipes and Interactions" on Kaggle. RAW_recipes.csv has about 230,000 recipes, each with a
list of ingredients, and RAW_interactions.csv has user ratings you can use for a side quest. Ingredient names are
messy free text, so some cleaning comes first.
The method is k-nearest neighbours (kNN). Turn every recipe into a vector with one entry per ingredient, then measure how close two vectors are. Here you use cosine similarity, which compares the angle between vectors:
If you scale every vector to length 1 first, cosine similarity is just the dot product, and scoring a query against every recipe is one matrix-vector product. sklearn uses cosine distance, which is , so the ranking is the same. Common ingredients like salt and butter would dominate the match, so you weight each ingredient by its inverse document frequency, , where is the number of recipes that use ingredient and is the number of recipes.
DATA · a public recipe dataset
Objectives
Read-only. Log in to update progress.
VICTORY CONDITIONS
- Recall@10 against sklearn NearestNeighbors with cosine distance is 1.0 on 1,000 random queries (ties broken by index on both sides). Record your batched queries per second with `python tools/mlarena.py record BL-04 "<your queries/s>"`.
- The query recipe itself is excluded from its own results.
- The README reports queries per second for your single, batched and sklearn searches, and shows three example recommendations you think are good and one you think is bad, with a reason.
Side quests
Terms in plain words
- Nearest neighbours
- Answering a query by finding the stored items closest to it under some distance.
- Cosine similarity
- The cosine of the angle between two vectors. It compares direction and ignores length, so a long recipe and a short one with the same mix still match.
- TF-IDF weighting
- Giving rare ingredients more weight than common ones, so sharing saffron counts for more than sharing salt.
- Sparse matrix
- A matrix stored as only its non-zero entries. Each recipe uses about ten of thousands of ingredients, so most entries are zero.
- Recall@10
- Of the true ten nearest neighbours, the fraction your search returned. 1.0 means you found all ten.