BitRabbit Engineers show you how to identify dishes through machine learning models!

Engineeringdishes, logic guidance

The culture of a region and the local delicaciesare always inseparable. This applies to small villages or large cities, eachwould have their unique “taste”.


While traveling foreign countries, restraint menus often have extravagant and misleading titles. This can often lead to dissatisfaction or confusion for the ordered food. So as a tech nerd, is it possible to use machine learning models to predict the taste of dishes through ingredients?

It is actually not hard to implement. As long as the machine learning method can build, train and test the model, the optimized model will be selected through evaluation matrix, and mapping between the materials used and dishes can be realized. To achieve the desired functionality, we need to perform the following three steps.

Enter and analyze the data

Build the model

Model prediction

Let’s take Italian dishes as an example. Inthe following graph, “id” represents different ingredients and “cuisine” is the menu title.

The data is first extracted, and the recipe nodes are as follows. It contains a set of recipes, dish types and ingredient lists.

Features and targets are then assigned to “train_ingredients”and “train_targets” respectively. Through Statistical analysis, we can find the 10 most used ingredients, and add their frequency and name to the“sum_ingredients” dictionary. Through the sample data, the top 10 most frequently used materials in the Italian cuisine can also be calculated, and the material name and the number of occurrences are assigned to the “italian_ingredients”dictionary.

The results can then be visualized by matplotlib. Through data analysis, you can get a lot of interesting information. For example, the most used ingredients in Brazilian cuisine are onions, olive oil, and lemon. In China, lemons are obviously not frequently used in home cooking. The most used ingredients are sauce, sesame oil, cornstarch and so on. Soy sauce can be reasonably predicted to have a large correlation to China’s number one material!

 

 

Japan's delicacies sake and soy sauce arealso on the list. In Russia, butter is an essential ingredient and an importantsource of energy for the ferocious people in the cold weather. So according toour newfound information, if you like butter, potatoes and milk, go to the UK!

 

(picture remark: Just use Der Song brandfor soy sauce!)

ModelBuilding

Model building is a little more complicated. It mainly follows four steps:

Word filtering

Trait extraction

Data sorting and rearrangement

Train the model

In the process of training the model, you need to try different parameters and pick the model with the best generalization. By training the model, the score on the validation set can be calculated. The higher the score, the higher the classification accuracy(percentage of correctly classified dishes). Once completed, you have  a successful model!

Model Prediction

In the test file test.json, the format of the recipe is the same as train.json, only the dish type is deleted, because it is the target variable we want to predict.

In conclusion, the process of predicting a cuisine through ingredients is not complicated. What we aim to accomplish is the improvement of code, model optimization, and accuracy of classification and matching. If the data cannot be effectively cleaned and sorted, many French dishes may be misclassified as Italian dishes.

YOU CAN TRY TO APPLY THIS METHOD ANYWHERE YOURSELF! 

  • 1
Block
Add Reply
Feedback |
expand

Still do not know how to handle??

Add Reply
expand
You should login to reply
You will reward to {{ username }}

Available Balance: {{balance}}

≈ $ {{usdtAmount.toFixed(2)}} (The reward commission rate is 10.0%)

New Favorite Bag

Add To Favorite You can create multiple favorites and classify the topics. Please select the favorites you want to add.
{{ favoriteBag.title }} {{ favoriteBag.favorites_count }}Topics

{{ text }} OK
fa-bars fa-arrow-up