# Dynamic Personalized Recipe Recommendations Based on Facial Health Recognition
## 3 Research Methods
### Collaborative Filtering Recommendation Algorithm Based on LFM  
The recommendation algorithm based on collaborative filtering is currently the most widely used. Its basic idea is to discover user preferences by mining user historical data and predict the products that users may prefer for recommendation. This article uses a model-based recommendation algorithm and applies the LFM model (latent factor model, latent semantic model) proposed by [PERSON], [PERSON] [17], etc. to predict and recommend user preferences. This model is closely related to singular value decomposition (SVD). This is a mature technique for identifying latent semantic factors in information retrieval, and its structure is shown in Figure 4.  
The LFM algorithm is a recommendation algorithm based on matrix decomposition. It decomposes the high-dimensional user-item rating matrix into two matrices, maps users  
Figure 4: Recommendation algorithm structure diagram based on LFM.  
and items to a low-dimensional space, and changes the potential semantic relationship between users and items in the subspace, thereby capturing the latent characteristics of user items for prediction and recommendation. The schematic diagram is shown in Figure 5.  
The P matrix is the User-LF (user-latent factor matrix). The Q matrix is the LF-Item (latent factor-item matrix), and the R matrix is the User-Item (user-item preference matrix) matrix. The core idea of the LFM model is to reduce the dimensionality of the R high-order matrix through matrix decomposition and decompose it into two matrices, P and Q. LFM associates items and users through implicit factors and calculates user's interest in item i:  
\[\text{R}_{ui}=\text{PQ} \tag{5}\]  
First, one needs to learn the training data set to obtain the P and Q matrices, restore the R matrix through calculation, predict the vacant values in the original data set, and fill them in. F is the number of hidden factors:  
\[\widehat{R}_{ui}=\sum_{f=1}^{F}P_{u,f}Q_{i,f} \tag{6}\]  
\(P_{(u,f)}\) and \(Q_{(u,f)}\) represent the f-th eigenvalue of the eigenvector of user u and item i, respectively. User 1's predicted liking value for item 1 is as follows:  
\[\text{R}_{11}=\text{P}_{11}\text{Q}_{11}+\text{P}_{12}\text{Q}_{12}+\text{P}_ {13}\text{Q}_{31} \tag{7}\]  
The way to learn the LFM model is to initialize the matrices P and Q, then solve for the minimization of the root mean square error (RMSE), and construct a minimization loss function to update the matrices P and Q. The loss function is defined as follows:  
\[Cost=\sum_{u,i\in R}(R_{ui}-\widehat{R}_{ui})^{2}=(\sum_{u,j\in R}R_{ui}\sum_ {f=1}^{F}P_{ui}\text{Q}_{if})^{2} \tag{8}\]  
To avoid overfitting the loss function during the iterative solution process, regularization parameters can be added. At this time, the loss function becomes  
\[Cost=\sum_{u,i\in R}(R_{ui}-\widehat{R}_{ui})^{2}=(\sum_{u,j\in R}R_{ui}\sum_ {f=1}^{F}P_{ui}\text{Q}_{if})^{2} \tag{9}\]  
Furthermore, the gradient descent method is used to optimize the loss function, which requires a partial derivative. The formula is as follows:  
\[\frac{\partial}{\partial_{P_{u,f}}}Cost=-2\sum_{u,i\in R}(R_{u,i}-\sum_{f=1}^{ F}P_{u,f}\text{Q}_{i,f})(-\text{Q}_{i,f})+2\lambda P_{u,f} \tag{10}\]  
\[\frac{\partial}{\partial_{P_{f,i}}}Cost=-2\sum_{u\in R}(R_{u,i}-\sum_{f=1}^{ F}P_{u,f}\text{Q}_{i,f})(-\text{Q}_{u,f})+2\lambda P_{uf} \tag{11}\]  
Figure 5: LFM algorithm principal diagram.  
We iteratively calculate the update matrices P and Q to find the optimal P matrix and Q matrix:  
\[P_{u,f}=P_{u,f}+\alpha\left[\left(R_{ui}-\sum_{f=1}^{F}P_{u,f}Q_{i,f}\right)Q_{i,f}-\lambda_{1}P_{u,f}\right] \tag{12}\]  
\[Q_{i,f}=Q_{i,f}+\alpha\left[\left(R_{ui}-\sum_{f=1}^{F}P_{u,f}Q_{i,f}\right)P_ {u,f}-\lambda_{2}Q_{i,f}\right] \tag{13}\]  
Here, \(\alpha\) is the learning rate, which represents the step size of iterative learning.