Design and Implementation of Nutritional Diet Analysis System Based on Cluster Analysis and Collaborative Filtering Algorithm

1 Introduction

Today, I would like to introduce to you a graduation design project to help previous students complete, the design and implementation of a nutritional and dietary analysis system based on cluster analysis and collaborative filtering algorithms .

1. The algorithm idea of ​​collaborative filtering

1.1. Inadequacies in content-based recommendation

The content-based recommendation method is easy for users to understand, simple and effective, but its shortcomings are also very obvious.

  • It requires that the content must be able to extract meaningful features, and requires that the content of these features have a good structure
  • The recommendation accuracy is low, and there is little difference between items with the same content characteristics. For these reasons, content-based recommendations are often mixed with other methods in recommender systems.

1.2. Thought derivation of collaborative filtering algorithm

For example, if you want to watch a movie, but don't know which one to watch, what would you do?

  • Ask friends with similar interests around you to see what good movies they have recommended recently. (based on user)
  • Look at the similarity of movies, for example, if you like to watch zombie movies, then you will find movies with zombies or zombies in the movie title. (item based)

For example, if you go to a toy store to choose a toy for a little boy, how should you choose?

  • I see most of the little boys are playing with Transformers, how about getting him a Transformers? (based on user)
  • I know this little boy has a lot of LEGO models, how about getting him one of the latest builds? (item based)

From this, the collaborative filtering algorithm idea can be deduced, as follows:

  • Collaborative filtering algorithm is based on the above ideas, mainly including user-based collaborative filtering recommendation algorithm and item-based collaborative filtering recommendation algorithm.
  • The core idea of ​​the item-based collaborative filtering algorithm: recommend to users items similar to the items they liked before, user U purchased item A, and recommend items B / C / D similar to user U and A
  • The core idea of ​​the user-based collaborative filtering algorithm is to first calculate the similarity between user U and other users, then take the most similar users to U, and recommend the items they have purchased to user U.

1.3. Steps to use the collaborative filtering algorithm

  1. Collect user preferences.
  2. Find similar users or items.
  3. Calculate referrals.
  4. Evaluate

1.4. Points to pay attention to when using collaborative filtering algorithm

The item-based collaborative filtering here is different from the previous content-based recommendation algorithm. The content-based recommendation algorithm only considers the content characteristics of the item, while the collaborative filtering includes item + user

The user-based collaborative filtering here is different from the previous demographics-based recommendation algorithm. The demographics-based recommendation algorithm considers the user's basic attributes (user portrait), and the user-based collaborative filtering considers the user's perception of items. Evaluation (favorite)

Collaboration: Continuous interaction between users, between users and websites, etc., slowly filtering out items that they are not interested in, so as to meet their own needs.

2. Collaborative filtering recommendation method

Collaborative filtering and content-based comparison of these two methods:

  • Content based (CB) mainly uses the content features of items rated by users, while Collaborative Filtering (CF) can also use the content of items rated by other users.

  • CF can solve some limitations of CB

    • When the content of the item is incomplete or difficult to obtain, it is still possible to give recommendations based on the feedback of other users
    • CF is based on the evaluation quality of items between users, avoiding the interference of CB on the quality judgment of items that may be caused by relying only on content
    • CF recommendation is not limited by content, as long as other similar users show interest in different items, CF can recommend items with very different content to users (but there is some internal connection)

Classification of collaborative filtering methods:

  • Collaborative filtering based on neighbors:

    • User-based (User-CF)
    • Item-based (Item-CF)
  • Model-based collaborative filtering:

    • Singular value decomposition (SVD)
    • Latent Semantic Analysis (LSA)
    • Support Vector Machines (SVMs)

3. Neighbor-based collaborative filtering

3.1. What is neighbor-based collaborative filtering

  • User-based collaborative filtering (UserCF): Recommend to users what other users like that are similar to users.
  • Item-Based Collaborative Filtering (ItemCF): Recommend other items similar to what the user likes.
  • The neighbor-based recommendation system is based on the same "word-of-mouth" criteria, as shown below, should I recommend "Titanic" to Cary? the answer is yes

3.2. User-based CF

User A likes items that user C likes, we think that user A is similar to user C,

Then the things that user C likes may also be liked by user A, so the items that user C likes are recommended to user A.

The thoughts are summarized as follows:

  • The basic principle of user-based collaborative filtering recommendation is to find the "neighborhood" user group similar to the current user's taste and preference according to all users' preferences for items, and recommend the items preferred by the neighbors

  • In general applications, the algorithm of calculating "K-Nearest Neighbors" is used; based on the historical preference information of these K neighbors, recommendations are made for the current user

  • User-CF and Demographics-Based Recommendation Mechanism

    • Both calculate the similarity of users and calculate recommendations based on similar "neighborhood" user groups
    • The difference between them is how to calculate the similarity of users: the mechanism based on demographics only considers the characteristics of users themselves, while the collaborative filtering mechanism based on users can calculate the similarity of users on the data of users' historical preferences. The assumption is that users who like similar items are likely to have the same or similar tastes and preferences

The pseudocode of the core algorithm of the model is expressed as follows:

Based on the core algorithm, the user commodity matrix is ​​completed:

Predict the user's score for unrated items, and then sort them in descending order for recommendation.

3.3. Item-based CF

Users who like item A also like item C, then we think that item A is similar to item C,

Then users who like item A may also like item C, so item C is recommended to users who like item A.

The thoughts are summarized as follows:

  • The basic principle of item-based collaborative filtering recommendation is similar to user-based, just use all users' preferences for items, find the similarity between items and items, and then recommend similar items to users based on the user's historical preference information

  • Item-CF and content-based (CB) recommendation

    • In fact, they are all based on item similarity prediction and recommendation, but the similarity calculation method is different. The former is inferred from the user's historical preference, while the latter is based on the attribute feature information of the item itself.
  • The same is collaborative filtering, how to choose between user-based and item-based strategies?

    • For e-commerce, movie, and music websites, the number of users t is much greater than the number of items
    • For news sites, the number of articles (news texts) may be greater than the number of users

First

2 Design outline

4.2 The overall module of the system
System functions
1. Provide an operable platform for merchants;
2. In the system, the nutritional content of dishes added by merchants can be analyzed;
3. Users need to log in and register their own personal accounts;
4. Provide users with ordering meals System;
5. Users can query the nutritional content of food on the nutrition query interface.
6. Users can query their own historical diet records.
7. Users can enter each meal by themselves to obtain a comparison between the corresponding nutrition card and the standard nutrition card.
Catering system module functions:
user registration: mainly to realize the user registration function.
User login: The monitoring object enters relevant personal information to log in to the system. After successful login, it will enter the main interface of the system.
Search: You can query the nutritional content of various ingredients.
Background management part The background of the system is mainly responsible for the regular maintenance of the system database and the addition and modification
of food and dishes by nutritionists. The following is a brief description of its main functions: Food information management: adding, deleting and updating food types and food information Inquire. Dishes information management: add, delete and query the types of dishes and dish information. Breakfast information management: add, delete and query breakfast types and dish information. Functions of nutrition analysis system: Dietary analysis: The monitored object can enter the dietary analysis interface through the main interface. The dietary analysis is mainly based on the dietary information entered by the user to realize the dietary analysis of the monitored object and display the results of the dietary analysis. Automatic catering: According to the current state of the user and the user's choice of staple food, fruit, etc., automatically select dishes, and give the results of automatic catering and the nutrient content of the dishes. User Preferences: display and modify the dietary preferences of the monitoring object, including preferences and taboos.








User Suggestion: Display the suggestions put forward by the monitoring object and provide the way for users to make suggestions.

4.2 Overall module diagram of the system
insert image description here

4.2.1 Registration and login module
Users need to log in before using the system. When logging in, the account number and password entered by the user will be detected. If it exists, it will be verified for correctness. If it does not exist, it will prompt to register. When the user registers, the account number entered by the user will be detected. If the same account number exists in the database, the registration cannot be performed. After the registration is completed, it will prompt that the registration is successful and ask whether to return to login. The detailed login and registration flow chart is as follows:
insert image description here
insert image description here

4.3 Flowchart of Registration and Login Module
4.2.2 Order Module
In the order module, there is a dietary nutrition analysis system to help users better start from the source and improve their dietary health to a certain extent. The user needs to choose the type of meal in advance before starting to order. The system will choose from the existing dishes according to the user's choice. However, excessive consumption of a single type will still affect health, so after submitting the menu, the system will automatically Evaluate dishes and make recommendations. The ordering flow chart is as follows:

4.4 Flow chart of the order module
4.2.3 User module
The user fills in the personal health status in the personal information, and the system recommends the corresponding diet type according to the user's health; the user can query the recent diet status in the historical record; the dietary nutrition analysis system will After the user completes the meal, a nutrition form is given, and this form is also available for viewing in the history; users can search for the nutritional content of ingredients in the query unit so that they can adjust themselves when the system is not convenient for calculation, and the system will also provide a nutrition calculator , for the user's own use.

4.5 User Module Use Case Diagram
4.3 System Algorithm Module
Dietary Nutrition Analysis System mainly uses two algorithms: clustering algorithm and web crawler. Among them, the clustering algorithm mainly solves the problem of system recommended recipes, and uses the clustering algorithm to draw similar data together to achieve the purpose of simplification , while the crawler is to solve the problem of nutritional data sources, crawl the authoritative open source nutritional information on the Internet through web crawler technology, and then reintegrate the data through data processing methods to meet the needs of the system. This time, the technology of theme web crawler will be adopted. Compared with general web crawlers, the goal of theme web crawlers is to crawl specific topic pages and filter irrelevant pages, which is characterized by specialization and precision. Topical web crawlers can reduce system consumption and save broadband resources [9].

4.6 Flow chart of crawler algorithm module
insert image description here
insert image description here

3 Key technologies of the system

Use springboot, vue, mysql, mybaties, typescript, html, css, js, etc. for development

4 Development Tools

Development tools mainly include: idea, jdk1.8, maven, mysql5.7, Navicat, etc.

5 code display

@RequestMapping("/strategy")
@RestController
@Scope("prototype")
public class StrategyController {
    
    
    @Autowired
    private StrategyService strategyService;
    @Value("${web.upload-path}")
    private String path;

    @RequestMapping("/findPage")
    public ObjDat<Strategy> findPage(Strategy strategy, @RequestParam(value="page", defaultValue="1") int page, @RequestParam(value="limit", defaultValue="10") int limit){
    
    
        return strategyService.findPage(strategy,page-1,limit);
    }

    @RequestMapping("/edit")
    public JsonResult edit(HttpServletRequest request, Strategy strategy) throws IOException {
    
    
        User user=(User)request.getSession().getAttribute("user");
        if(user==null){
    
    
            return JsonResult.error("请登录");
        }
        String str=strategyService.edit(request,strategy);
        if(str.equals("成功")){
    
    
            return JsonResult.success("操作成功");
        }else{
    
    
            return JsonResult.error("操作失败");
        }
    }

6 System function description

Project function demo
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_42135426/article/details/128536304