How to match the seasonings and ingredients of delicious meals? Let's take a look at the correlation analysis

How to match the seasonings and ingredients of delicious meals? Let's take a look at the correlation analysis


Some time ago, the editor launched a recipe generation gadget, which is to create a ui interface by crawling and removing the recipe data from the kitchen, and randomly generating recipes of three dishes and one soup. Original:

"Python crawls the menu to generate recipes, you don’t have to worry about cooking and buying food"

This time, the editor still uses the recipes from the kitchen, rewrites a crawler to crawl more than 5000 recipe data, and uses this data to call the correlation analysis model Apriori to find out how the ingredients and seasonings are matched when cooking. Use this as a reference, maybe you will transform into a top chef~

data collection

Open the lower kitchen:

Climb the above picture, home cooking, fast hand dishes, meal, breakfast, fish, eggs, soup, baking, staple food, noodles, vegetarian food, the above types of recipes.

Take home cooking as an example, crawl the name, ingredients, score, and type of each recipe on each page, and save it as a csv:

Copy the first recipe name on the first page, right click [view webpage source code] to search for the recipe name, you can search:

Explain that the webpage is a static webpage, which can be crawled directly, which is not complicated, and the specific realization of obtaining the source code for viewing.

Apriori model

Association analysis is a simple and practical technology in data mining. Through in-depth analysis of data sets, it finds the associations between things, mines frequently occurring combinations, and describes the patterns and laws of the simultaneous appearance of objects in the combinations.

For example, conduct correlation analysis on supermarket shopping data, discover the relationship between different products purchased by customers, analyze customer buying habits, design product combinations, and formulate corresponding marketing strategies to create demand and increase sales Amount, to create additional income.

In this project, discover how the ingredients and seasonings of the recipe are matched, and refer to the public’s collocation to make more delicious meals~

The Apriori algorithm is one of the most famous association rule mining algorithms, and we use it for association rules.

The Apriori algorithm is mainly implemented by the following functions to calculate strong association rules:

Detailed implementation to obtain source code reference, after implementation, the data set needs to be processed into the required format, and then the function is called:

The output format is as follows:

Take a result as an example for interpretation:

frozenset({'fine sugar','egg'}) --> frozenset({'milk'}) Support 0.021773 confidence: 0.620879

It means that there are fine sugar/eggs in the ingredients at the same time, and the probability of milk is 62%, and the probability of this happening according to the situation is 2.1%

From this, we can combine fine sugar, eggs, and milk to make a delicious meal~

The other results are also interpreted in the same way. Of course, you still have to actually cook the dishes before you can experience it. Maybe the next chef born is you~~

Source code acquisition

Follow the WeChat public account " Kinxia Learning Python ", reply " Associated Ingredients " to get

Reference: How to match the seasonings and ingredients of delicious meals? Let’s take a look at the correlation analysis-Cloud + Community-Tencent Cloud