Recommendation method based on user's food safety rating and food similarity
By obtaining user food safety rating data, calculating the scoring weights and generating a similarity matrix, the problems of food recommendation effects and inefficiency in the prior art are solved, and more efficient and objective food recommendations are achieved.
Patent Information
- Application Number
- CN202111003703.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-30
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2041-08-30
AI Technical Summary
In the prior art, in food recommendations, the recommendation effect based on neighborhood methods is low and the recommendation efficiency based on model methods is low, and the chronological order and sparsity of user score data are not effectively considered, which affects the authenticity and reliability of the recommendations.
By obtaining the user's safety rating data for food, calculating the scoring weight, and combining neighborhood-based collaborative filtering methods and machine learning models, a food similarity matrix is generated, and the chronological order and sparseness of the scoring data are considered to optimize the recommended effect.
It improves the recommendation effect and efficiency, enhances the authenticity and objectivity of the food similarity matrix, reduces the model training time, and avoids overfitting.
Smart Images

Figure CN113888252B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of food recommendation, and in particular to a recommendation method based on user's food safety grade rating and food similarity. Background Art
[0002] The emergence and rapid development of e-commerce has greatly changed people's traditional concept of buying food. It makes online transactions easier by providing a large amount of food and detailed food information. However, as the number of foods that meet user needs increases dramatically, how to effectively and efficiently help users identify the foods that best suit their personal preferences becomes a problem, especially given the user's safety rating value data for food. The widely used TopN recommendation system is to generate a list of recommended items for users through recommendation algorithms. In recent years, various TopN recommendation algorithms have been studied. These algorithms can be divided into two categories: neighborhood-based collaborative filtering methods and model-based collaborative filtering methods. The neighborhood-based method only needs the user's behavior data to directly calculate the similarity of users or items. Among them, the method based on the neighborhood of items can generate recommendations very quickly and is simple to implement, but it achieves this at the expense of recommendation effect. The model-based method needs to learn the feature data of users or items through the user's behavior data, especially the method based on the latent factor model. Although this machine learning model will generate better recommendation quality, it will also incur a higher time cost in the parameter learning of the model. On the other hand, both the neighborhood-based and model-based methods directly use the user's specific ratings of items in the selection of data samples, ignoring various factors that may affect the user's rating. The user's previous ratings of some items are likely to mislead the current item's rating and thus affect the authenticity and reliability of the rating. In this case, the similarity between items is affected by the order of user ratings, resulting in the user's subjective rating not being able to objectively reflect the similarity between items. Summary of the invention
[0003] The purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art and propose a recommendation method based on user food safety grade ratings and food similarities. The method overcomes the problems of low recommendation effect based on neighborhood methods and low recommendation efficiency based on model methods. The similarity matrix of foods is learned from user food safety grade rating data, and sparsity is introduced into the similarity matrix while considering the time sequence of the rating data, so that recommendations can be generated effectively.
[0004] To achieve the above object, the technical solution provided by the present invention is: a recommendation method based on the user's food safety grade score and food similarity, comprising the following steps:
[0005] 1) Obtaining the user's rating data on food; each piece of rating data includes user ID, food ID, safety level rating value, and rating time;
[0006] 2) For the rating data of the same user ID, the rating weight of each rating data is calculated according to the order of the rating time and the security level rating value;
[0007] 3) The user ID, food ID, safety level score value and score weight of the scoring data are input into the machine learning model for parameter training. After the parameter training is completed, a food similarity matrix is obtained. Finally, the user's scoring data and the food similarity matrix are used to calculate and generate the user's food recommendation list to recommend food to the user.
[0008] Further, in step 1), the user's food rating data refers to the user's historical rating data used to input into the machine learning model for training, and the rating data includes user ID, food ID, safety level rating value and rating time; wherein, the user ID is the user's unique identifier, and different user IDs represent different users; the food ID is the unique identifier of the food, and different food IDs represent different foods; the safety level rating value refers to the safety level rating value of the food represented by the food ID by the user represented by the user ID; and the rating time refers to the time when the user rates the food safety level.
[0009] Furthermore, in step 2), the scoring data of different users are grouped according to user ID; the scoring data of the same user ID are arranged in order according to their scoring time, and for each scoring data after sorting, its scoring weight value is processed according to the following three situations: ① If the security level scoring value of the previous scoring data is the highest scoring value, the scoring weight of the current scoring data is 1.2; ② If the security level scoring value of the previous scoring data is the lowest scoring value, the scoring weight of the current scoring data is 0.8; ③ The scoring weights of the first scoring data and other data are 1.
[0010] Further, in step 3), the rating data of all users are converted into a rating matrix, where each row of the rating matrix represents a user, each column represents a food, and each value of the matrix represents the safety level rating of the food in the column given by the user in the row; the rating matrix is input into the machine learning model for parameter training, and the matrix form objective function of the machine learning model is:
[0011]
[0012] Where R is a rating matrix with m rows and n columns, m represents the number of users, n represents the number of foods, each row of the rating matrix represents a user, and each column represents a food; W is a food similarity matrix with n rows and n columns obtained through training, n represents the number of foods, and each row or column represents a food; each value in the food similarity matrix represents the similarity between the food in that row and the food in that column, and its value is greater than or equal to zero. At the same time, the values on the diagonal of the food similarity matrix are all zero; ||·||1 is the L1 norm of the matrix; ||·|| F is the Frobenius norm of the matrix; constants β and λ are regularization parameters;
[0013] Since each column in the food similarity matrix W is independent, each column of the food similarity matrix can be trained in parallel, and the matrix form objective function can be decomposed into:
[0014]
[0015] Among them, R j is the jth column of the rating matrix R, W j is the jth column of the food similarity matrix W; ||·||2 is the L2 norm of the vector; ||·||1 is the L1 norm of the vector; constants β and λ are regularization parameters; in order to reduce the time of model parameter training, the safety level score value of each scoring data is multiplied by its corresponding scoring weight, and the neighborhood-based collaborative filtering method is used to calculate the safety level score value of each scoring data and R in the scoring matrix. j The columns with high similarity are selected in minimizing the objective function. j Columns with high similarity are fitted with the objective function;
[0016] The formula for calculating the error value of each scoring data in the objective function is:
[0017] error=weight(r ui -predict)
[0018] Among them, r ui represents the safety rating value of the u-th row and i-th column in the rating matrix; predict represents the predicted safety rating value, which is obtained by calculating the inner product of the u-th row of the rating matrix and the i-th column of the food similarity matrix; considering the scoring weight of the scoring data, the weight error value of each scoring data is:
[0019] WeightError=weight*error
[0020] Among them, weight is the scoring weight of the scoring data; the machine learning model will minimize the weight error value of all scoring data;
[0021] After all users’ rating data are input into the machine learning model for parameter training, a food similarity matrix W will be obtained; the predicted safety rating value of the unrated food i for user u is calculated as:
[0022] PredictRate ui =R u W i
[0023] Among them, R u represents the vector of the u-th row in the rating matrix, i.e., the rating data of user u; W i Represents the vector in the i-th column of the food similarity matrix, that is, the similarity value between food i and other foods; after calculating the user's predicted safety level scores for all unrated foods, the predicted safety level scores are sorted, and multiple foods with the highest scores are selected to recommend to the user to complete the recommendation process.
[0024] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0025] 1. The present invention combines the use of a neighborhood-based collaborative filtering method while training a machine learning model, thereby reducing the model training time and improving the recommendation effect.
[0026] 2. The present invention uses the L1 norm, L2 norm and Frobenius norm to ensure the sparsity of the matrix obtained by model training and prevent overfitting.
[0027] 3. The present invention calculates the weight value of the scoring data based on the time sequence of the scoring data, thereby improving the authenticity and objectivity of the food similarity matrix obtained by model training and improving the recommendation effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 The figure is a logical flow diagram of the method of the present invention.
[0029] Figure 2 The present invention is a flowchart for calculating the scoring weight. DETAILED DESCRIPTION
[0030] The present invention will be further described below in conjunction with specific embodiments.
[0031] like Figure 1 As shown, the recommendation method based on the user's food safety grade score and food similarity provided in this embodiment uses a collaborative filtering method based on the neighborhood while training a machine learning model, learns the food similarity matrix from the user's food score data, considers the time sequence of the score data, and introduces sparsity into the similarity matrix, so that recommendations can be generated effectively, which includes the following steps:
[0032] 1) Obtain the user's rating data on food, that is, the user's historical rating data used to input the machine learning model for training. The rating data includes user ID, food ID, safety level rating value and rating time. Among them, user ID is the unique identifier of the user, and different user IDs represent different users; food ID is the unique identifier of food, and different food IDs represent different foods; safety level rating value refers to the safety level rating value of the food represented by the food ID by the user represented by the user ID; rating time refers to the time when the user rated the food.
[0033] 2) Group the rating data of different users according to user ID. Arrange the rating data of the same user ID in order according to their rating time. For each rating data after sorting, see Figure 2 As shown, the scoring weight values are processed according to the following three situations: ① If the security level scoring value of the previous scoring data is the highest scoring value, the scoring weight of the current scoring data is 1.2; ② If the security level scoring value of the previous scoring data is the lowest scoring value, the scoring weight of the current scoring data is 0.8; ③ The scoring weights of the first scoring data and other data are 1.
[0034] 3) Convert all users’ rating data into a rating matrix. Each row of the rating matrix represents a user, each column represents a food, and each value of the matrix represents the safety rating of the food in that column given by the user in that row. Input the rating matrix into the machine learning model for parameter training. The matrix form objective function of the machine learning model is:
[0035]
[0036] Where R is a rating matrix with m rows and n columns, m represents the number of users, n represents the number of foods, each row of the rating matrix represents a user, and each column represents a food; W is a food similarity matrix with n rows and n columns obtained through training, n represents the number of foods, and each row or column represents a food; each value in the food similarity matrix represents the similarity between the food in that row and the food in that column, and its value is greater than or equal to zero. At the same time, the values on the diagonal of the food similarity matrix are all zero; ||·||1 is the L1 norm of the matrix; ||·|| F is the Frobenius norm of the matrix; the constants β and λ are regularization parameters.
[0037] Since each column in the food similarity matrix W is independent, each column of the food similarity matrix can be trained in parallel, and the matrix form objective function can be decomposed into:
[0038]
[0039] Among them, R j is the jth column of the rating matrix R, W j is the jth column of the food similarity matrix W; ||·||2 is the L2 norm of the vector; ||·||1 is the L1 norm of the vector; constants β and λ are regularization parameters. In order to reduce the time of model parameter training, the neighborhood-based collaborative filtering method is used in advance to calculate the score matrix and R j The columns with high similarity are selected in minimizing the objective function. j Columns with high similarity are fitted with the objective function.
[0040] The formula for calculating the error value of each scoring data in the objective function is:
[0041] error=weight(r ui -predict)
[0042] Among them, r ui represents the safety rating value of the uth row and ith column in the rating matrix; predict represents the predicted safety rating value, which is obtained by calculating the inner product of the uth row of the rating matrix and the ith column of the food similarity matrix. Considering the scoring weight of the scoring data, the weight error value of each scoring data is:
[0043] WeightError=weight*error
[0044] Among them, weight is the scoring weight of the scoring data. The machine learning model will minimize the weight error value of all scoring data.
[0045] After all users' rating data are input into the machine learning model for parameter training, a food similarity matrix W will be obtained. The predicted safety rating value of the unrated food i for user u is calculated as:
[0046] PredictRate ui =R u W i
[0047] Among them, R u represents the vector of the u-th row in the rating matrix, i.e., the rating data of user u; W i Represents the vector of the i-th column in the food similarity matrix, that is, the similarity value between food i and other foods. After calculating the predicted safety rating values of all unrated foods by the user, the predicted safety rating values are sorted, and multiple foods with the highest scores are selected and recommended to the user. Finally, the user's food recommendation list is calculated and generated through the user's rating data and the food similarity matrix, and the food is recommended to the user.
[0048] In summary, after adopting the above scheme, the present invention breaks through the problems of low recommendation effect based on the neighborhood method and low recommendation efficiency based on the model method, and calculates the rating weights while considering the time sequence of user rating data, so that it can effectively generate recommendations and improve the recommendation effect.
[0049] The above-described embodiments are only preferred embodiments of the present invention and are not intended to limit the scope of implementation of the present invention. Therefore, all changes made according to the shape and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A recommendation method based on user's food safety rating and food similarity, characterized in that: The following steps are involved: 1) Obtaining the user's rating data on food; each piece of rating data includes user ID, food ID, safety level rating value, and rating time; 2) For the rating data of the same user ID, the rating weight of each rating data is calculated according to the order of the rating time and the security level rating value; 3) Input the user ID, food ID, safety rating value and rating weight of the rating data into the machine learning model for parameter training. After the parameter training is completed, a food similarity matrix is obtained. Finally, the user's rating data and food similarity matrix are used to calculate and generate the user's food recommendation list to recommend food to the user, as follows: The rating data of all users are converted into a rating matrix. Each row of the rating matrix represents a user, each column represents a food, and each value of the matrix represents the safety level rating of the food in the column given by the user in that row. The rating matrix is input into the machine learning model for parameter training. The matrix form objective function of the machine learning model is: Where R is a rating matrix with m rows and n columns, m represents the number of users, n represents the number of foods, each row of the rating matrix represents a user, and each column represents a food; W is a food similarity matrix with n rows and n columns obtained through training, n represents the number of foods, and each row or column represents a food; each value in the food similarity matrix represents the similarity between the food in that row and the food in that column, and its value is greater than or equal to zero. At the same time, the values on the diagonal of the food similarity matrix are all zero; ||·||1 is the L1 norm of the matrix; ||·|| F is the Frobenius norm of the matrix; constants β and λ are regularization parameters; Since each column in the food similarity matrix W is independent, each column of the food similarity matrix can be trained in parallel, and the matrix form objective function can be decomposed into: Among them, R j is the jth column of the rating matrix R, W j is the jth column of the food similarity matrix W; ||·||2 is the L2 norm of the vector; ||·||1 is the L1 norm of the vector; constants β and λ are regularization parameters; in order to reduce the time of model parameter training, the safety level score value of each scoring data is multiplied by its corresponding scoring weight, and the neighborhood-based collaborative filtering method is used to calculate the safety level score value of each scoring data and R in the scoring matrix. j The columns with high similarity are selected in minimizing the objective function. j Columns with high similarity are fitted with the objective function; The formula for calculating the error value of each scoring data in the objective function is: error=weight(r ui -predict) Among them, r ui represents the safety rating value of the u-th row and i-th column in the rating matrix; predict represents the predicted safety rating value, which is obtained by calculating the inner product of the u-th row of the rating matrix and the i-th column of the food similarity matrix; considering the scoring weight of the scoring data, the weight error value of each scoring data is: WeightError=weight*error Among them, weight is the scoring weight of the scoring data; the machine learning model will minimize the weight error value of all scoring data; After all users’ rating data are input into the machine learning model for parameter training, a food similarity matrix W will be obtained; the predicted safety rating value of user u for unrated food i is calculated as: PredictRate ui =R u W i Among them, R u represents the vector of the u-th row in the rating matrix, i.e., the rating data of user u; W i Represents the vector in the i-th column of the food similarity matrix, that is, the similarity value between food i and other foods; after calculating the user's predicted safety level scores for all unrated foods, the predicted safety level scores are sorted, and multiple foods with the highest scores are selected to recommend to the user to complete the recommendation process.
2. The recommendation method based on user's food safety grade score and food similarity according to claim 1, characterized in that: In step 1), the user's food rating data refers to the user's historical rating data used to input into the machine learning model for training, and the rating data includes user ID, food ID, safety level rating value and rating time; wherein, the user ID is the user's unique identifier, and different user IDs represent different users; the food ID is the unique identifier of the food, and different food IDs represent different foods; the safety level rating value refers to the safety level rating value of the food represented by the food ID, which is assigned by the user represented by the user ID; and the rating time refers to the time when the user rates the food safety level.
3. The recommendation method based on user's food safety grade score and food similarity according to claim 1, characterized in that: In step 2), the scoring data of different users are grouped according to the user ID; the scoring data of the same user ID are arranged in order according to their scoring time, and for each scoring data after sorting, its scoring weight value is processed according to the following three situations: ① If the security level scoring value of the previous scoring data is the highest scoring value, the scoring weight of the current scoring data is 1.2; ② If the security level scoring value of the previous scoring data is the lowest scoring value, the scoring weight of the current scoring data is 0.8; ③ The scoring weights of the first scoring data and other data are 1.
Citation Information
Patent Citations
Time utility recommendation method based on interest change of user
CN106682121A
Collaborative filtering-based personalized recommendation method
CN111414555A