# Enhancing Collaborative Filtering-Based Recommender System Using Sentiment Analysis
## 3 Materials and Methods
### Recommendation Algorithms  
The recommender system has been implemented using CF methods. The dataset was partitioned into two portions, with the larger part, 80%, utilized for training purposes, while the remaining 20% was utilized as a test set for evaluation purposes. Figure 4: Sentiment analysis steps based on Bi-LSTM model. To prepare the training data for use in a CF model, the data need to be transformed into a specific format. This involves converting the data into a mn \(\times\) n array where m represents the number of products and n the number of users. Having transformed the training dataset into a matrix of product features, we constructed our recommender system by utilizing a collaborative filtering method. To predict products that have not been rated by a particular user, we need a metric to identify similarities between users (user-based) or between items (item-based). One commonly used metric is cosine similarity (Equation (4)) [40]. \[\mathrm{s}(d_{a},d_{i})=\frac{\sum_{i}w_{ji}\cdot w_{ja}}{\sqrt{\sum_{i}w_{ji}^{ 2}}\cdot\sqrt{\sum_{j}w_{ja}^{2}}} \tag{4}\]  
where \(w_{ji}\) and \(w_{ja}\) are components of vectors \(d_{a}\) and \(d_{i}\), respectively. Next, we perform a cosine similarity-based prediction of ratings. The ratings of either the most similar items (in item-based approach) or users (in user-based approach) were utilized to anticipate the rating of a current user for a particular item that has not yet been rated. \[P_{ij}=\tilde{r}_{i}+\frac{\sum_{u}\mathrm{s}(i,u)\left(r_{ij}-r_{i}\right)}{ \sum_{u}\mid\mathrm{s}(i,u)\mid\mid} \tag{5}\]  
where:  
* \(P_{ij}\) is the predicted rating for item \(j\) by user \(i\). * \(r_{ij}\) denotes the rating provided by user \(i\) for item \(j\). * \(\tilde{r}_{i}\) is the average rating by user \(i\). * \(s(i,u)\) denotes the similarity between users \(i\) and \(u\). \[P_{ui}=\frac{\sum_{j}r_{uj}\cdot\mathrm{s}(i,j)}{\sum_{j}s(i,j)} \tag{6}\]  
where:  
* \(p_{ui}\) is the predicted rating for user \(u\) and item \(j\). * \(r_{uj}\) denotes the actual rating that user \(u\) gave to item \(j\). * \(s(i,j)\) denotes the similarity between items \(j\) and \(i\). Equation (5) is used for user-based collaborative filtering, and Equation (6) is used for item-based collaborative filtering. \begin{table}
\begin{tabular}{l c} \hline \hline
**Metric** & **Formula** \\ \hline Accuracy & \\  & \(\frac{TN+TP}{TP+TN+FP+FN}\) \\ \hline F1-score & \\  & \(\frac{2*TP}{2*TP+FP+FN}\) \\ \hline AUC & \\  & \(\frac{S_{p}-n_{p}(n_{n}+1)/2}{n_{p}n_{n}}\) \\  & (For binary classification problems.) \\  & where \(S_{p}\) represents the total of positive examples arranged in rank order, while \(n_{p}\) and \(n_{n}\) stand for the quantity of positive and negative examples, respectively. \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Model performance measurement. * Combining sentiment analysis model with traditional collaborative filtering methods for the final prediction: We incorporated sentiment analysis into our recommendation system to classify the sentiment of reviews as negative or positive, and then we used this sentiment information as an additional feature in our system. The goal of incorporating sentiment analysis into the recommendation system is to enhance the predictive accuracy by utilizing the implicit feedback information embedded in the sentiment of the reviews. Figure 5 displays an illustration of how star ratings can be combined with textual reviews in recommendation systems. This integration can result in an improvement in the overall performance of the recommendation system compared to utilizing star ratings alone. The integrated result is presented as follows:  
\[H=\alpha\times R+(1-\alpha)\times S \tag{7}\]  
where:  
* \(R\): Predicted rating for a user on a product by CF techniques without using SA. * \(S\): Predicted sentiment score using the Bi-LSTM sentiment model. * \(\alpha\): The weight given for each term in the equation.