Introduction
In the self-introduction in my blog’s sidebar, there is a line that says "Kitchen Enthusiast." Although I am not particularly good at cooking, the kitchen is indeed one of my hobbies. Of course, I have many interests—mathematics, physics, astronomy, computer science, etc. I like them all and want to learn them all, which often makes me a "jack of all trades, master of none." As mentioned in previous articles, data mining is also a hobby of mine. What interesting results might emerge when the two hobbies of data mining and cooking meet?
I did exactly that: I wrote a simple crawler to scrape a batch of recipe data from the Home Cooking directory of Meishi China and performed a simple data analysis. (I would like to express my sincere gratitude to Meishi China. I chose them because their data is relatively standardized.) The data analysis was performed on my company’s high-performance servers, which made the process exceptionally smooth.
In total, I collected 18,209 recipes, containing 9,700 types of ingredients (including main ingredients, side ingredients, and seasonings; some may be duplicated due to non-standard naming). Of course, compared to the standards of "Big Data" in many other fields, this volume of data is negligible. However, in the kitchen—a place where Big Data is rarely involved—it should be considered quite substantial.
Simple Statistics
The simplest thing to do is to perform a statistical analysis of the ingredients. Can you guess what appears most frequently?
Even without any expertise in gourmet food, readers should be able to guess that the most frequent item is definitely salt! Salt is often called the "King of a Hundred Flavors," and very few dishes are made without it. Next is cooking wine, followed by light soy sauce—all of which are seasonings or condiments. This shows that Chinese cuisine is very particular about its ingredients, with a vast array of seasonings. Among main ingredients, potatoes appear at the 28th position, pork belly at the 38th, and so on.
Salt: 11200
Cooking wine: 4601
Light soy sauce: 4413
Ginger: 3671
Green onion: 2854
Chicken essence: 2579
White sugar: 2440
Sugar: 2303
Oil: 2297
Garlic: 2058
Egg: 1924
Soy sauce: 1883
Dark soy sauce: 1625
Pepper powder: 1619
Sichuan pepper: 1571
Carrot: 1324
......
Word2Vec Results
By treating each recipe as a tokenized sentence, we can use this "corpus" to train a Word2Vec model. What interesting results can we get? (Even if we don’t find anything, it doesn’t matter; it’s all about exploration.) The entire training process was surprisingly fast, taking less than a second.
For readers who are unfamiliar, Word2Vec is a model that can transform words into real-valued vectors. Words can only be processed by a computer once they are converted into numbers. The vectors obtained by Word2Vec have special properties; for example, the cosine similarity between two word vectors represents the degree of similarity between the two words.
Once the Word2Vec model is trained, the first thing we can do is compare the similarity between two words. Some results are quite ordinary, such as:
>>> pd.Series(model.most_similar(u'Pork Belly'))
0 (Ribs, 0.882662177086)
1 (Pork belly with skin, 0.866969347)
2 (Dried beans, 0.864805340767)
3 (Quail eggs, 0.850470840931)
4 (Pickled cabbage, 0.842567443848)
5 (Duck leg, 0.841659963131)
6 (Sanhuang chicken, 0.837065219879)
7 (Old master stock, 0.828875720501)
8 (Chicken gizzards, 0.827436089516)
9 (Crucian carp, 0.826281666756)
However, there are some surprising results, for example:
>>> pd.Series(model.most_similar(u'Chicken'))
0 (Corn, 0.939546108246)
1 (Agrocybe aegerita, 0.914446234703)
2 (Sweet corn, 0.888315618038)
3 (Fresh shrimp, 0.88096922636)
4 (Brown beech mushroom, 0.870144784451)
5 (Red carrot, 0.86743336916)
6 (Pasta, 0.864846467972)
7 (Kewpie salad dressing, 0.860477805138)
8 (Pork tenderloin, 0.85995388031)
9 (White mushroom, 0.855247914791)
Here, "Chicken" and "Corn" are surprisingly highly similar! This indicates that there must be a story to tell between them.
What is the reason behind this? The principle of the Word2Vec model lies in word co-occurrence. Therefore, the reason for this phenomenon might be: 1. Corn and chicken are often cooked together; 2. Corn and chicken are often cooked separately with similar ingredients. In fact, with a little observation, you will find that both are true; they are mainly used together to make soup, and their accompanying ingredients are similar:
Recipes containing Chicken (partial):
140 [Chicken, Maca, Goji berries, Red dates, Longan, Lotus seeds, Ginger]
144 [Chicken, Erjingtiao chili, Vegetable oil, Old ginger, Garlic, Dried chili, Sichuan pepper, Salt, Cooking wine, Light soy sauce, White sugar]
267 [Chicken, Potato, Green pepper, Onion, Flour, Ginger/Garlic, Small chili, Dark soy sauce, White sugar, Light soy sauce, Sichuan pepper/Star anise...]
313 [Chicken, Beer, Potato, Sichuan pepper, Star anise, Small chili, Ginger/Garlic, Light soy sauce, Dark soy sauce]
520 [Chicken, Breadcrumbs, Egg, Glutinous rice flour, Light soy sauce, Oyster sauce, Salt, Pepper powder]
961 [Cucumber/Gourd, Chicken, Dried shrimp, Red dates, Ginger, Star anise, Green onion]
1005 [Glutinous rice, Chicken, Shrimp meat, Ginger strips, Chopped green onion, Light soy sauce, Oyster sauce, Pepper powder, Starch]
1095 [Chicken, Egg white, Flour, Ginger, Garlic, Cooking wine, Salt, Black pepper]
1178 [Chicken, Milk, Salt, Pepper powder, Garlic powder, Low-gluten flour, Starch, Ice water, Crushed peanuts, Cooking oil, Malt...]
1551 [Chicken, Button mushroom, Onion, Dried chili, Green onion, Ginger, Garlic, Sichuan pepper, Rock sugar, Salt]Recipes containing Corn (partial):
106 [Chicken wings, 2-3 pieces of ribs, Salt, Ginger, Celery, Cooking wine, Carrot, Corn, Red dates, Ginseng slices, Cordyceps...]
172 [Yam, Corn, Pork spine, Salt, Ginger]
316 [Pork bone, Corn, Tiegun Yam, Red dates]
441 [Corn, Tomato, Tofu, Vegetable oil, Old ginger, Leek, Sichuan pepper, Salt, Beef powder]
450 [Yam, Ribs, Carrot, Ginger, Cooking wine, Thirteen-spice powder, Goji berries, Corn, Green onion sections, Star anise, Fine salt]
483 [Red carrot, Pumpkin, Celery, Corn, Broccoli, Pine nuts]
485 [Lotus root, Carrot, Shiitake mushroom, Peanut, Red dates, Corn, Ginger slices]
509 [Ribs, Corn, King oyster mushroom, Goji berries, Bay leaf, MSG, Salt]
789 [Chicken wings, Enoki mushroom, Shiitake mushroom, White mushroom, Drumstick mushroom, Nameko mushroom, Dried scallops, Cordyceps flower, Corn, Salt, Ginger, ...]
828 [Diced meat, Corn, Carrot, Fish sauce, Light soy sauce, Salt, Peanut oil]
It seems our experiment has indeed produced some interesting results. From our experience alone, it might not be easy to discover the correlation between "Chicken" and "Corn," but through data mining, as long as there is enough data, interesting findings can be uncovered. Similar results include: the similarity between Beef and Squid reached 96%, and the similarity between Beef and Potato was 91%, and so on! You can look at the data below and try to explain the result for Beef and Squid:
Recipes containing Beef (partial):
46 [Beef, Carrot, Scallion, Curry powder, Salt, Coconut milk, Potato, Onion, Ginger, Korean soy sauce, Thai fish sauce]
70 [Beef, Wood ear mushroom, Carrot, Red bell pepper, Green pepper, Scallion, Ginger strips, Minced garlic, Peanut oil, Pixian broad bean paste, ...]
148 [Beef, Green pepper, Onion, Ginger/Garlic, Sichuan pepper, Bay leaf, Star anise, Dark soy sauce, Light soy sauce, Cumin powder, Pepper powder]
272 [Beef, Taro, Star anise, Bay leaf, Cinnamon, Sichuan pepper, Ginger, Chili, Rock sugar, Green onion, Salt, Cooking wine, Light soy sauce]
290 [Beef, Carrot, Onion, Red wine, Broth, Salt, Pepper powder, Tomato sauce, Butter, Flour, Bay leaf...]
404 [Beef, Bay leaf, Star anise, Sichuan pepper, Ginger/Garlic, Oyster sauce, Light soy sauce, Salt, Chicken essence]
433 [Bean sprouts, Beef, Green onion, Green pepper, Oyster sauce, Salt]
452 [Beef, White sugar, Sichuan pepper, Sauce, Salt, Carrot, Soy sauce, Star anise, Garlic, Cooking wine]
455 [Beef, Dried yellow soybean paste, Thirteen-spice powder, Cinnamon powder, Star anise powder, Sichuan pepper powder, Ginger powder, Salt, Master stock]
534 [Potato, Beef, Salt, Cooking wine, Light soy sauce, Garlic, Ginger, Coriander]Recipes containing Squid (partial):
187 [Squid, Rib sauce, Sugar, Oyster sauce, Onion, Chili, Sweet pepper]
284 [Squid, Sweet pepper]
374 [Squid, Onion, White sesame, Garlic chili sauce, Green onion, Ginger, Scallion, BBQ sauce]
996 [Onion, Sponge gourd, Squid, Oil, Salt, Soy sauce, Sugar, Cooking wine, Oyster sauce]
1468 [Squid, Round onion, Lettuce, Yipinxian soy sauce, Garlic chili sauce, Sugar, Oyster sauce, Cooking wine, Salt, Chicken essence]
1502 [Squid, Green and red chili, Ginger/Garlic, Salt, Sugar, Light soy sauce, Starch, Sichuan pepper]
1577 [Squid, Bell pepper, Soybean paste, Ginger]
1619 [Shrimp, White clams, Squid, Straw mushroom, Tom Yum paste, Fresh lemon leaves, Fish sauce, Coconut milk, Sugar]
1796 [Razor clams, Squid, Chives, White pepper powder, Cooking wine, Salt, Ginger]
1798 [Squid, Cumin, Salt, Peanut oil]
Apriori Association Rules
Another potentially meaningful attempt is to mine association rules. Since the data volume is not large, I simply used the Apriori algorithm.
Before mining the rules, I performed some preprocessing: 1. Removed salt, because the count for salt is too high. If not removed, many of the mined rules would contain salt, which would simply tell us "remember to add salt when cooking"—a meaningless rule. 2. Removed ingredients that appeared only once. These ingredients have too little information and are unlikely to appear in rules; removing them reduces the computational load.
After this processing, if we set the support (the proportion of rule occurrences) to 0.01 and the confidence (the reliability of the rule) to 0.8, we get the following rules:
| Rule | Support | Confidence |
|---|---|---|
| Cooking wine – Green onion – Garlic \rightarrow Ginger | 0.019935 | 0.912060 |
| Sugar – Green onion – Garlic \rightarrow Ginger | 0.011203 | 0.879310 |
| Cooking wine – Sichuan pepper – Green onion \rightarrow Ginger | 0.010544 | 0.872727 |
| Cooking wine – Dark soy sauce – Green onion \rightarrow Ginger | 0.011643 | 0.868852 |
| Star anise – Green onion \rightarrow Ginger | 0.016695 | 0.858757 |
| Cooking wine – Sugar – Green onion \rightarrow Ginger | 0.013345 | 0.846690 |
| Cooking wine – Light soy sauce – Garlic \rightarrow Ginger | 0.013345 | 0.840830 |
| Light soy sauce – Green onion – Garlic \rightarrow Ginger | 0.012741 | 0.840580 |
| Dark soy sauce – Garlic \rightarrow Ginger | 0.013290 | 0.831615 |
| Sichuan pepper – Green onion \rightarrow Ginger | 0.019221 | 0.825472 |
| Cooking wine – Garlic \rightarrow Ginger | 0.032511 | 0.821082 |
| Cooking wine – Light soy sauce – Green onion \rightarrow Ginger | 0.019057 | 0.816471 |
| Dark soy sauce – Green onion \rightarrow Ginger | 0.017903 | 0.808933 |
| Cooking wine – Green onion \rightarrow Ginger | 0.050799 | 0.805749 |
These mean: if cooking wine, green onion, and garlic appear, then ginger should also be added; if sugar, green onion, and garlic appear, remember to add ginger; and so on. These rules all end with ginger, telling us when ginger needs to be added. In cooking, these rules are quite meaningful (especially for beginners). These rules also indicate that ginger is a very important seasoning in Chinese cuisine.
We can slightly relax the conditions to try and mine more rules. By lowering the confidence requirement to 0.7, we get:
| Rule | Support | Confidence |
|---|---|---|
| Green onion – Garlic \rightarrow Ginger | 0.038497 | 0.799316 |
| Cinnamon – Bay leaf \rightarrow Star anise | 0.018013 | 0.782816 |
| Rock sugar – Cinnamon \rightarrow Star anise | 0.010160 | 0.780591 |
| Sichuan pepper – Garlic \rightarrow Ginger | 0.014169 | 0.779456 |
| Light soy sauce – Bay leaf \rightarrow Star anise | 0.010874 | 0.770428 |
| Cooking wine – Cinnamon \rightarrow Star anise | 0.014938 | 0.764045 |
| Cinnamon \rightarrow Star anise | 0.031633 | 0.761905 |
| Cinnamon – Sichuan pepper \rightarrow Star anise | 0.015267 | 0.761644 |
| Dark soy sauce – Bay leaf \rightarrow Star anise | 0.011423 | 0.759124 |
| Pepper powder – Green onion \rightarrow Ginger | 0.014498 | 0.758621 |
| Cinnamon – Dark soy sauce \rightarrow Star anise | 0.013070 | 0.757962 |
| Sugar – Green onion \rightarrow Ginger | 0.022297 | 0.753247 |
| Cinnamon – Light soy sauce \rightarrow Star anise | 0.011148 | 0.751852 |
| Cooking wine – Bay leaf \rightarrow Star anise | 0.012411 | 0.750831 |
| Sichuan pepper – Bay leaf \rightarrow Star anise | 0.014608 | 0.745098 |
| Green onion – Vinegar \rightarrow Ginger | 0.011203 | 0.744526 |
| Rock sugar – Light soy sauce \rightarrow Dark soy sauce | 0.010929 | 0.742537 |
| Bay leaf \rightarrow Star anise | 0.028777 | 0.738028 |
| Ginger – Cinnamon \rightarrow Star anise | 0.011917 | 0.735593 |
| Starch – Green onion \rightarrow Ginger | 0.011038 | 0.730909 |
| Ginger – Bay leaf \rightarrow Star anise | 0.010215 | 0.723735 |
| Ginger – Sugar – Garlic \rightarrow Green onion | 0.011203 | 0.720848 |
| Sugar – Garlic \rightarrow Ginger | 0.015542 | 0.712846 |
| Light soy sauce – Green onion \rightarrow Ginger | 0.032402 | 0.704898 |
| Green onion – Soy sauce \rightarrow Ginger | 0.017244 | 0.700893 |
If the rules about ginger are too common, then the rules obtained here should be more meaningful. For example, "Cinnamon – Bay leaf – Star anise," "Rock sugar – Cinnamon – Star anise," "Cinnamon – Light soy sauce – Star anise," etc. These combinations should be recipes related to braised dishes (Lu Wei). These recipes might not be clear to an average kitchen enthusiast, but through association rules, they can be unearthed.
There are also some rules with higher confidence but slightly lower support:
| Rule | Support | Confidence |
|---|---|---|
| Cooking wine – Dark soy sauce – Green onion – Garlic \rightarrow Ginger | 0.005602 | 0.953271 |
| Cooking wine – Sichuan pepper – Green onion – Garlic \rightarrow Ginger | 0.005547 | 0.952830 |
| Cooking wine – Sugar – Green onion – Garlic \rightarrow Ginger | 0.007634 | 0.952055 |
| Cooking wine – Cinnamon – Green onion \rightarrow Ginger | 0.005711 | 0.936937 |
| Cooking wine – Light soy sauce – Green onion – Garlic \rightarrow Ginger | 0.007743 | 0.921569 |
| Cinnamon – Sichuan pepper – Green onion \rightarrow Ginger | 0.005217 | 0.913462 |
| Cooking wine – White sugar – Garlic \rightarrow Ginger | 0.005931 | 0.805970 |
| Cooking wine – Green onion \rightarrow Ginger | 0.050799 | 0.805749 |
| Rock sugar – Dark soy sauce – Bay leaf \rightarrow Star anise | 0.005162 | 0.803419 |
These are more detailed and precise seasoning recipes. Note that these are results automatically mined by the computer; our computer is the chef.
Conclusion
This article attempts to combine two of my interests—data mining and the kitchen—to obtain some seemingly interesting results. In fact, some interesting results were indeed obtained. Of course, they include some of my own understanding of the kitchen, but whether they are truly interesting is for the readers to judge.
This type of mining is essentially text mining, or can be categorized under the field of Natural Language Processing (NLP). As seen in this article, the methods used are basically NLP methods. Readers familiar with the field will know that the difficulty in NLP lies in feature construction—that is, how to represent a word numerically. This article made an attempt, but due to reasons like insufficient data, the conclusions are not necessarily accurate. This attempt might not be exceptionally successful, but the process is informative. Perhaps more data could increase the value of the research results.
From an intuitive perspective, this kind of mining is meaningful. We can extract information we didn’t know from an ordinary field; perhaps we already knew this information but never paid attention to it. But the computer helped us discover it, allowing us to face it or utilize it better. Data mining can help us live better. Indeed, data mining technology should be popularized and democratized, because our lives are our most important source of data.
Finally, I am sharing the scraped data: Recipe_Data.zip
Please include the original address when reposting: https://kexue.fm/archives/3587
For more detailed reposting matters, please refer to: "Scientific Space FAQ"