# Application of Improved K-Means Algorithm in Collaborative Recommendation System

Authors: Hui Jing
Journal: Journal of Applied Mathematics
 (2022)

---

## Abstract

With the explosive growth of information resources in the age of big data, mankind has gradually fallen into a serious “information overload” situation. In the face of massive data, collaborative filtering algorithm plays an important role in information filtering and information refinement. However, the recommendation quality and efficiency of collaborative filtering recommendation algorithms are low. The research combines the improved artificial bee colony algorithm with K-means algorithm and applies them to the recommendation system to form a collaborative filtering recommendation algorithm. The experimental results show that the MAE value of the new fitness function is 0.767 on average, which has good separation and compactness in clustering effect. It shows high search accuracy and speed. Compared with the original collaborative filtering algorithm, the average absolute error value of this algorithm is low, and the running time is only 50 s. It improves the recommendation quality and ensures the recommendation efficiency, providing a new research path for the improvement of collaborative filtering recommendation algorithm.


---

## Body

## 1. Introduction

With the continuous advancement of technology and the rapid development of the Internet, rich information resources are inundating everyone all the time, and both information producers and consumers are facing huge challenges [1]. Information producers need to deliver their information precisely to eligible target users, while as information consumers have to select effective data that satisfies themselves among the redundant and complicated mass of data, so the recommendation system appears. By analyzing users’ historical data and actively providing them with news and products that meet their needs and interests, recommendation systems are able to filter information and provide users with personalized information services. It is playing an important role in various areas of social life such as current business systems [2]. Collaborative filtering recommendation algorithm is a comprehensive filtering algorithm, which takes the similarity of the item’s attributes or user’s ratings as the basis for personalized recommendation. It can handle unstructured complex objects without first extracting the content of the item. Collaborative filtering recommendation algorithms are capable of handling unstructured data and are gradually occupying a central position in recommendation systems. However, current collaborative filtering recommendation algorithms face a series of significant problems due to their own algorithmic characteristics, such as difficulties in ensuring real-time algorithm performance when dealing with huge data volumes. Ortega et al. developed a hybrid recommendation algorithm with multiclass classification algorithms and executed based on user rating behavior to improve the prediction and recommendation quality [3]. In addition, the artificial bee colony algorithm (ABC) has been effectively used in improving clustering performance due to its fewer parameters, simplicity, and ease of implementation and global merit seeking capability [4]. However, the K-means algorithm is prone to fall into local extremum and rely too much on the initial point selection, and the algorithm center determination time complexity is high. Therefore, in the second part of the study, the literature review of collaborative filtering algorithms at home and abroad is described. In the first section of the third part, the artificial bee colony algorithm is improved and combined with the K-means algorithm. The second section of the third part is a collaborative filtering recommendation method based on the improved colony K-means algorithm. The fourth part is to verify the application effect of the proposed method. The fifth part is the conclusion of the study.


## 2. Related Work

In recent years, collaborative filtering recommendation algorithms and artificial bee colony K-means clustering models have received a great deal of attention among related professionals at home and abroad, and researchers have proposed many new methods for this purpose. Al-Bakri and Hassan proposed a modest approach to enhance data prediction by applying a user-based collaborative filtering algorithm to clustered data, and the results showed that the algorithm improved the recommendation system scalability [5]. Selvi and Sivasankar used supervised adaptive genetic networks to locate the most popular data points in clusters as a way to ensure simple and effective recommendations and reduce error rates. The effectiveness of the algorithm is demonstrated through experiments on the Netflix dataset [6]. Yang et al. proposed a time-weighted collaborative filtering algorithm with improved small-batch K-means clustering for sparse rating matrices and derived user scores with high recall and rating prediction accuracy to address shortcomings such as user interest bias in traditional collaborative filtering algorithms [7]. Wang et al. proposed a collaborative filtering algorithm incorporating temporal factors and applied it to score prediction and nearest neighbor selection with a time-weighted function. The results showed that the algorithm has good operational performance [8]. Najafabadi et al. performed neighbor selection for each user through user-based fuzzy clustering and a new similarity metric, and the results showed that it can improve the accuracy of recommendations to users [9]. Garanayak et al. developed a new recommendation system using K-means and item-based collaborative filtering techniques to filter out desired information segments based on people’s preferences and concerns for the information [10].Ashaduzzaman et al. proposed a clustering method that integrates multicriteria ratings into traditional recommender systems, rating in multidimensional situations such as auxiliary information, contextual information, and multiple criteria, and the results showed that the method was able to produce effective recommendations [11]. Ali and Wasid used the K-means algorithm for clustering and incorporated user-based rating criteria. The Mahalanobis distance metric was used to calculate the clustering similarity and generate a neighborhood set. Experiments showed that the algorithm improved the quality of recommendations [12]. Li et al. proposed a collaborative filtering algorithm based on category priority to address the problems of scalability and data sparsity of collaborative filtering recommendation algorithms and proposed a user-item priority ratio to calculate the priority ratio matrix. The recommendation accuracy of this algorithm was improved by 2.81% through experiments on the MovieLens dataset [13]. Onuean et al. set up recommendation items based on memory-based collaborative filtering techniques and used K-means clustering to cluster each data. The experimental results showed that the method has high accuracy in prediction and recommendation [14]. Zhu et al. proposed a fuzzy clustering-based method that evaluates the prediction-driven uncertainty and classifies based on existing data. Experimental results show that the method outperforms traditional collaborative filtering recommendation algorithms [15]. Chakraborty et al. addressed the problem of large bias in clustering results caused by initial guesses of clustering centers by combining the K-means algorithm with a volume metric algorithm and genetic arithmetic as a way to predict the optimal value of initial clustering centers. Experimental results showed that the algorithm improved prediction efficiency [16]. Daoudi et al. developed a new parallel K-means algorithm using a graphics processing unit to select the initial center of mass by using an open computing language in the programming environment and performing the initialization steps on the CPU in parallel. Experimental results showed that the method reduced the running time while maintaining quality [17].In summary, the K-means algorithm has significant advantages in user clustering, and most researchers have also used K-means clustering by introducing it into traditional collaborative filtering recommendation algorithms to improve recommendation efficiency, but less research has been conducted on the combination of artificial bee colony algorithms with K-means. Therefore, the study will improve the swarm K-means model as a way to enhance the performance of recommendation systems.


## 3. Collaborative Filtering Recommendation Algorithm Based on Swarm K-Means Clustering Model

### 3.1. Improvement of Bee Colony Algorithm Based on K-Means Clustering Model

The artificial bee colony (ABC) algorithm is a colony intelligence optimization algorithm developed on the basis of simulating the foraging behavior of honey bee colonies. It has the advantages of simple operation, easy implementation, fast convergence, and few control parameters and is widely used in optimization problems such as function optimization and data mining [18]. The K-means algorithm, a distance-based hard clustering algorithm, is easy to end up with a local optimum and difficult to apply to data classification, despite its fast clustering speed and strong local search capability [19]. K-means objective criterion function is the distance from each point to the cluster cent. Solving for the extreme value of the function can iteratively adjusts the rules. K-means algorithm first selects k number of clusters and a dataset including n data, the initial cluster centers are selected randomly, the number of data samples is k, and the remaining nodes are n−k; then, they are divided into the class where the nearest centroid is located according to the distance of the remaining nodes to each initial cluster center. The new centroids of each cluster are obtained by calculating again, and it is judged whether the new cluster centroids change, i.e., whether the criterion function converges. If it converges, the algorithm ends; otherwise, it continues to the next iteration, as shown in Figure 1.Figure 1
Schematic diagram of K-means.The K-means algorithm divides the data samples mainly by measuring similarity, and the Euclidean distance formula for similarity between samples is given in(1)dxi,xj=∑k−1nxik−xjk2.In Equation (1), xj and xi are the data samples in the dataset, while xik and xjk are the data samples in the k cluster. The objective criterion function of the K-means algorithm is the mean squared error, as shown in
(2)E=∑j=1c∑k=1njxk−mj2.In Equation (2), xk represents the data elements in the selected sample, E represents the sum of the mean squared deviations of the data elements, and mj represents the cluster center of the j cluster. Cluster analysis is judged by the sum of squares of errors, as shown in Equation (3), with the aim of obtaining an optimal set of divisions that are as independent as possible between clusters and as compact as possible within clusters.
(3)J=∑i=1k∑j=1xj∈Cindisxj,ci2,ci=1Ni∑j=1xj∈Cinxj.In Equation (3), xj represents a data sample in the class Ci, ci is the mean value of the data objects selected in the cluster Ci, Ni represents the number of data objects in the ith cluster, and disxj,ci represents the Euclidean distance between ci and xj. The artificial bee colony algorithm is introduced. It is improved and combined with the K-means algorithm. The artificial bee colony algorithm is improved at three levels, fitness function, population initialization, and position update, and its conceptual correspondence with the K-means algorithm is shown in Table 1.Table 1
Comparison of bee colony optimization and K-means.
K-meansBee foraging behaviorCluster centerHoney source locationConvergence speed of clustering algorithmSearch and foraging speedAdvantages and disadvantages of clustering centerHoney source richnessCluster centers with high fitnessRich food sourcesThe initialization process of the artificial bee colony algorithm randomly generates nectar sources with twice the number of nectar sources already generated and randomly generates nectar source information within a given range of values. Finally, the fitness value of that source is calculated, as shown in(4)Xij=βj+rand0,1αj−βj,fitness=11+fitness,1+αβsfitness.In Equation (4), X is the nectar source information, fitness is the fitness value of the nectar source, rand0,1 is a random number between (0, 1), αj represents the upper limit of the j dimensional data, and βj is the lower limit of the j dimensional data. The conventional fitness function is shown in
(5)fitnessclassicalI=CNiJi.In Equation (5), fitnessclassicalI is the fitness value of the nectar source i, and CNi represents the number of points in the i cluster. In order to combine the improved artificial bee colony algorithm with the K-means algorithm, it is necessary to construct a fitness function that makes K-means more efficient and faster clustering. Considering the intraclass distance and the number of points contained in each cluster as an influence, then the new fitness formula is given in
(6)fitnessnewI=CNiJi+CKM.In Equation (6), CK represents the sum of the distances from other cluster centers to the cluster center I, and M represents the number of cluster centroids. The hired bee performs a neighborhood search at its current location and selects a nectar source as shown in
(7)Vij=Xij+θijXij−Xkj,Vij=XijfitnessVij≤fitnessXij,VijfitnessVij>fitnessXij.In Equation (7), V represents the velocity, θij is a random number between [-1, 1], and j is not equal to k. The ability of the swarm to obtain a higher quality honey source at a faster convergence rate depends on the location update formula. The existing artificial bee colony algorithm converges slowly in the later stages, so a global bootstrap factor is introduced and the new location update formula is shown in
(8)Vij=xij+rijxlj−xkj+θxbest,j−xij.In Equation (8), vij represents a new location near xij. l, k, and j are random numbers obtained from a random formula, k and l are both equal to or not equal to i and mutually exclusive, xbest,j represents the current highest quality food source, and rij is a random number between [-1,1] and θ∈ [0,1]. The formula for calculating the probability when the full hired bee search is complete is given in
(9)pi=fitnessnewI∑i=1NfitnessnewI.In Equation (9), pi represents the probability, and fitnessI is the new fitness function value. The new location update formula shows that when the optimal location in the population is far from the location of the individual, the next iteration of the individual’s search will increase the step size and approach the global optimal location at a faster rate, and vice versa, converge slowly. Commonly used external evaluation metrics for clustering are shown in
(10)Fa=2PaRaPa+Ra.In Equation (10), Ra is the completeness rate, Pa is the accuracy rate, andFa is the external evaluation index of clusters. The weighted average of the F-measure of each category a gives F, as shown in
(11)F=∑aFa⋅a∑aa.In Equation (11), a represents the number of all objects in the classificationa. So the flow chart of the improved algorithm is shown in Figure 2.Figure 2
K-means clustering algorithm flow based on improved bee colony algorithm.As can be seen from Figure2, the improved algorithm has eight basic steps. Firstly, the number of scout bees, followers, and leaders is initialized, with equal numbers of followers and leaders; secondly, the initial colony is clustered, and the new fitness formula is used to derive fitness values, which are arranged in descending order. Thirdly, the leader bees search the vicinity of the current location to obtain a new food source and then choose whether to keep the new food source based on the size of the fitness value compared to the original food source. Step 4 is to calculate the probability of following the bee Pi. Step 5 is to perform a nearest neighbor search after the following bee has selected the leader bee. Step 6 is to obtain the cluster center relative to the new food source after the nearest neighbor iteration and perform K-means clustering on the population. Step 7 is to check if there are any unrenewed food sources afterLimit iterations. Finally, depending on whether the number of iterations satisfies the termination condition, the algorithm is terminated algorithm or move to step 2.


### 3.2. Recommendation Algorithm Based on Improved Clustering Model

Collaborative filtering recommendation algorithm can filter information that cannot be automatically analyzed by the machine and has the ability to recommend new information. It has gradually become one of the most widely used and successful recommendation algorithms in the recommendation system [20]. However, collaborative filtering recommendation algorithms face the problems of data sparsity and cold start. The sparsity problem refers to the fact that users voluntarily give few reviews, and the common reviews of the same item by different users are even more scarce, so it tends to have low accuracy when calculating the similarity between items and between users. The cold start problem refers to the lack of historical evaluation data from users when new users and new items enter the recommender system or when a brand new system is just launched [21]. The problem of data sparsity is mainly compensated by filling in other useful information, which is a way to build effective models of user interests and item characteristics. Alternatively, the scoring data can be preprocessed by machine learning methods, such as matrix partitioning, matrix decomposition, and clustering, on the basis of existing data [22]. The cold-start problem then relies on the incorporation of trust relationships, background knowledge, and demographic information when calculating similarity, the integrated inclusion of item content information, and the proposal of new similarity metrics. The improved swarm K-means algorithm is therefore introduced into the collaborative filtering algorithm, where users are first clustered according to swarm K-means; i.e., the historical behavioral data of the initial user is analyzed and processed accordingly to find the set of users with similarities to the interest preferences of the user to be recommended. After clustering, clusters are obtained, and each cluster has a cluster center corresponding to it [23]. Then, the similarity between the target user and other users is calculated, and then, the recommendation list of the target user is formed based on the rating information of the nearest neighbor users. The principle of the algorithm is shown in Figure 3.Figure 3
Schematic diagram of collaborative filtering recommendation based on bee colony K-means clustering.As can be seen from Figure3, in the recommendation of user U, user clustering is performed based on the user’s attribute information to obtain k clusters, and when user U exists in the class cluster j, the nearest neighbor set of T of U is obtained in the class cluster j based on the user-item rating matrix and calculated by similarity [24]. The similarity between users is mainly expressed by the cosine angle between user vectors, the magnitude of which is positively related to the degree of user similarity. The formula for calculating the similarity between the two is given in
(12)simu,v=cosv⟶⋅u⟶=v⟶⋅u⟶v⟶⋅u⟶=∑i=1nRvi⋅Rui∑i=1nRvi2⋅∑i=1nRui2.In Equation (12), both u and v represent the representative user, u⟶ represents the rating obtained by the user in the un dimensional space, v⟶ is the rating obtained by the user v in the n dimensional space, and sim represents similarity. Since the rating scales differ between users, the difference in rating scales is compensated by introducing an average user rating in the cosine similarity calculation, i.e., subtracting the average user score on the item. The modified cosine similarity formula is shown in
(13)simu,v=∑i∈1rvi−rv¯⋅rui−ru¯∑i∈1rvi−rv¯2⋅∑i∈1rui−ru¯2.In Equation (13), rui represents the rating of user u on item i. rv¯ and ru¯ represent the average of the ratings of all items by user v and user u, respectively, i represents the elements in the item set, and i∈I. The items are then sorted in descending order of similarity, and a certain group of similar neighbors in the sort is selected together to form the set of nearest neighbors of the target user u. The predicted ratings of all items in the item set is shown in
(14)Pu,j=ru¯+∑v∈UNDsimv,u×rvj−rv¯∑v∈UNDsimv,u.In Equation (14), UND represents the set of nearest neighbors, Pu,j is the predicted score of user u on item j, and simu,v is the similarity between user v and user u. The predicted scores are then used to obtain a score table, and recommendations are made based on the score table to obtain a recommendation list. The performance of the recommendation system is determined by the user’s satisfaction level, which is also an indicator of the quality of the recommendation [25]. The most commonly used statistical accuracy measure is the mean absolute error (MAE), as shown in
(15)MAE=∑i=1NPui−QuiN.In Equation (15), Pu is the predicted rating scale from user u, Qu represents the actual rating scale, and N represents the number of test sets. The mean absolute error (MAE) is a measure of the difference between the true and predicted scores to measure the correctness. It is negatively correlated with the quality of the recommendation; i.e., a smaller MAE value means that the algorithm’s recommendation quality is better, and conversely, a larger MAE value means that the algorithm’s recommendation quality is worse.


## 3.1. Improvement of Bee Colony Algorithm Based on K-Means Clustering Model

The artificial bee colony (ABC) algorithm is a colony intelligence optimization algorithm developed on the basis of simulating the foraging behavior of honey bee colonies. It has the advantages of simple operation, easy implementation, fast convergence, and few control parameters and is widely used in optimization problems such as function optimization and data mining [18]. The K-means algorithm, a distance-based hard clustering algorithm, is easy to end up with a local optimum and difficult to apply to data classification, despite its fast clustering speed and strong local search capability [19]. K-means objective criterion function is the distance from each point to the cluster cent. Solving for the extreme value of the function can iteratively adjusts the rules. K-means algorithm first selects k number of clusters and a dataset including n data, the initial cluster centers are selected randomly, the number of data samples is k, and the remaining nodes are n−k; then, they are divided into the class where the nearest centroid is located according to the distance of the remaining nodes to each initial cluster center. The new centroids of each cluster are obtained by calculating again, and it is judged whether the new cluster centroids change, i.e., whether the criterion function converges. If it converges, the algorithm ends; otherwise, it continues to the next iteration, as shown in Figure 1.Figure 1
Schematic diagram of K-means.The K-means algorithm divides the data samples mainly by measuring similarity, and the Euclidean distance formula for similarity between samples is given in(1)dxi,xj=∑k−1nxik−xjk2.In Equation (1), xj and xi are the data samples in the dataset, while xik and xjk are the data samples in the k cluster. The objective criterion function of the K-means algorithm is the mean squared error, as shown in
(2)E=∑j=1c∑k=1njxk−mj2.In Equation (2), xk represents the data elements in the selected sample, E represents the sum of the mean squared deviations of the data elements, and mj represents the cluster center of the j cluster. Cluster analysis is judged by the sum of squares of errors, as shown in Equation (3), with the aim of obtaining an optimal set of divisions that are as independent as possible between clusters and as compact as possible within clusters.
(3)J=∑i=1k∑j=1xj∈Cindisxj,ci2,ci=1Ni∑j=1xj∈Cinxj.In Equation (3), xj represents a data sample in the class Ci, ci is the mean value of the data objects selected in the cluster Ci, Ni represents the number of data objects in the ith cluster, and disxj,ci represents the Euclidean distance between ci and xj. The artificial bee colony algorithm is introduced. It is improved and combined with the K-means algorithm. The artificial bee colony algorithm is improved at three levels, fitness function, population initialization, and position update, and its conceptual correspondence with the K-means algorithm is shown in Table 1.Table 1
Comparison of bee colony optimization and K-means.
K-meansBee foraging behaviorCluster centerHoney source locationConvergence speed of clustering algorithmSearch and foraging speedAdvantages and disadvantages of clustering centerHoney source richnessCluster centers with high fitnessRich food sourcesThe initialization process of the artificial bee colony algorithm randomly generates nectar sources with twice the number of nectar sources already generated and randomly generates nectar source information within a given range of values. Finally, the fitness value of that source is calculated, as shown in(4)Xij=βj+rand0,1αj−βj,fitness=11+fitness,1+αβsfitness.In Equation (4), X is the nectar source information, fitness is the fitness value of the nectar source, rand0,1 is a random number between (0, 1), αj represents the upper limit of the j dimensional data, and βj is the lower limit of the j dimensional data. The conventional fitness function is shown in
(5)fitnessclassicalI=CNiJi.In Equation (5), fitnessclassicalI is the fitness value of the nectar source i, and CNi represents the number of points in the i cluster. In order to combine the improved artificial bee colony algorithm with the K-means algorithm, it is necessary to construct a fitness function that makes K-means more efficient and faster clustering. Considering the intraclass distance and the number of points contained in each cluster as an influence, then the new fitness formula is given in
(6)fitnessnewI=CNiJi+CKM.In Equation (6), CK represents the sum of the distances from other cluster centers to the cluster center I, and M represents the number of cluster centroids. The hired bee performs a neighborhood search at its current location and selects a nectar source as shown in
(7)Vij=Xij+θijXij−Xkj,Vij=XijfitnessVij≤fitnessXij,VijfitnessVij>fitnessXij.In Equation (7), V represents the velocity, θij is a random number between [-1, 1], and j is not equal to k. The ability of the swarm to obtain a higher quality honey source at a faster convergence rate depends on the location update formula. The existing artificial bee colony algorithm converges slowly in the later stages, so a global bootstrap factor is introduced and the new location update formula is shown in
(8)Vij=xij+rijxlj−xkj+θxbest,j−xij.In Equation (8), vij represents a new location near xij. l, k, and j are random numbers obtained from a random formula, k and l are both equal to or not equal to i and mutually exclusive, xbest,j represents the current highest quality food source, and rij is a random number between [-1,1] and θ∈ [0,1]. The formula for calculating the probability when the full hired bee search is complete is given in
(9)pi=fitnessnewI∑i=1NfitnessnewI.In Equation (9), pi represents the probability, and fitnessI is the new fitness function value. The new location update formula shows that when the optimal location in the population is far from the location of the individual, the next iteration of the individual’s search will increase the step size and approach the global optimal location at a faster rate, and vice versa, converge slowly. Commonly used external evaluation metrics for clustering are shown in
(10)Fa=2PaRaPa+Ra.In Equation (10), Ra is the completeness rate, Pa is the accuracy rate, andFa is the external evaluation index of clusters. The weighted average of the F-measure of each category a gives F, as shown in
(11)F=∑aFa⋅a∑aa.In Equation (11), a represents the number of all objects in the classificationa. So the flow chart of the improved algorithm is shown in Figure 2.Figure 2
K-means clustering algorithm flow based on improved bee colony algorithm.As can be seen from Figure2, the improved algorithm has eight basic steps. Firstly, the number of scout bees, followers, and leaders is initialized, with equal numbers of followers and leaders; secondly, the initial colony is clustered, and the new fitness formula is used to derive fitness values, which are arranged in descending order. Thirdly, the leader bees search the vicinity of the current location to obtain a new food source and then choose whether to keep the new food source based on the size of the fitness value compared to the original food source. Step 4 is to calculate the probability of following the bee Pi. Step 5 is to perform a nearest neighbor search after the following bee has selected the leader bee. Step 6 is to obtain the cluster center relative to the new food source after the nearest neighbor iteration and perform K-means clustering on the population. Step 7 is to check if there are any unrenewed food sources afterLimit iterations. Finally, depending on whether the number of iterations satisfies the termination condition, the algorithm is terminated algorithm or move to step 2.


## 3.2. Recommendation Algorithm Based on Improved Clustering Model

Collaborative filtering recommendation algorithm can filter information that cannot be automatically analyzed by the machine and has the ability to recommend new information. It has gradually become one of the most widely used and successful recommendation algorithms in the recommendation system [20]. However, collaborative filtering recommendation algorithms face the problems of data sparsity and cold start. The sparsity problem refers to the fact that users voluntarily give few reviews, and the common reviews of the same item by different users are even more scarce, so it tends to have low accuracy when calculating the similarity between items and between users. The cold start problem refers to the lack of historical evaluation data from users when new users and new items enter the recommender system or when a brand new system is just launched [21]. The problem of data sparsity is mainly compensated by filling in other useful information, which is a way to build effective models of user interests and item characteristics. Alternatively, the scoring data can be preprocessed by machine learning methods, such as matrix partitioning, matrix decomposition, and clustering, on the basis of existing data [22]. The cold-start problem then relies on the incorporation of trust relationships, background knowledge, and demographic information when calculating similarity, the integrated inclusion of item content information, and the proposal of new similarity metrics. The improved swarm K-means algorithm is therefore introduced into the collaborative filtering algorithm, where users are first clustered according to swarm K-means; i.e., the historical behavioral data of the initial user is analyzed and processed accordingly to find the set of users with similarities to the interest preferences of the user to be recommended. After clustering, clusters are obtained, and each cluster has a cluster center corresponding to it [23]. Then, the similarity between the target user and other users is calculated, and then, the recommendation list of the target user is formed based on the rating information of the nearest neighbor users. The principle of the algorithm is shown in Figure 3.Figure 3
Schematic diagram of collaborative filtering recommendation based on bee colony K-means clustering.As can be seen from Figure3, in the recommendation of user U, user clustering is performed based on the user’s attribute information to obtain k clusters, and when user U exists in the class cluster j, the nearest neighbor set of T of U is obtained in the class cluster j based on the user-item rating matrix and calculated by similarity [24]. The similarity between users is mainly expressed by the cosine angle between user vectors, the magnitude of which is positively related to the degree of user similarity. The formula for calculating the similarity between the two is given in
(12)simu,v=cosv⟶⋅u⟶=v⟶⋅u⟶v⟶⋅u⟶=∑i=1nRvi⋅Rui∑i=1nRvi2⋅∑i=1nRui2.In Equation (12), both u and v represent the representative user, u⟶ represents the rating obtained by the user in the un dimensional space, v⟶ is the rating obtained by the user v in the n dimensional space, and sim represents similarity. Since the rating scales differ between users, the difference in rating scales is compensated by introducing an average user rating in the cosine similarity calculation, i.e., subtracting the average user score on the item. The modified cosine similarity formula is shown in
(13)simu,v=∑i∈1rvi−rv¯⋅rui−ru¯∑i∈1rvi−rv¯2⋅∑i∈1rui−ru¯2.In Equation (13), rui represents the rating of user u on item i. rv¯ and ru¯ represent the average of the ratings of all items by user v and user u, respectively, i represents the elements in the item set, and i∈I. The items are then sorted in descending order of similarity, and a certain group of similar neighbors in the sort is selected together to form the set of nearest neighbors of the target user u. The predicted ratings of all items in the item set is shown in
(14)Pu,j=ru¯+∑v∈UNDsimv,u×rvj−rv¯∑v∈UNDsimv,u.In Equation (14), UND represents the set of nearest neighbors, Pu,j is the predicted score of user u on item j, and simu,v is the similarity between user v and user u. The predicted scores are then used to obtain a score table, and recommendations are made based on the score table to obtain a recommendation list. The performance of the recommendation system is determined by the user’s satisfaction level, which is also an indicator of the quality of the recommendation [25]. The most commonly used statistical accuracy measure is the mean absolute error (MAE), as shown in
(15)MAE=∑i=1NPui−QuiN.In Equation (15), Pu is the predicted rating scale from user u, Qu represents the actual rating scale, and N represents the number of test sets. The mean absolute error (MAE) is a measure of the difference between the true and predicted scores to measure the correctness. It is negatively correlated with the quality of the recommendation; i.e., a smaller MAE value means that the algorithm’s recommendation quality is better, and conversely, a larger MAE value means that the algorithm’s recommendation quality is worse.


## 4. Application Effect Analysis of Collaborative Filtering Recommendation Algorithm Based on Bee Colony K-Means Clustering

An experimental analysis of the improved collaborative filtering recommendation algorithm was conducted. The configuration environment of the experiment includes Intel (R) Core (TM) i5-6200U CPU @ 2.30 GHz 2.40 GHz, 8.0 GB memory, 500G hard disk, Windows 10 64 bit operating system. Development platform is PyCharm platform based on Python 3.8.4. PyCharm is a powerful Python compiler. Its greatest advantage is that it combines multiple libraries (such as Matplotlib, pandas, and NumPy), which is simple and convenient. The experimental dataset was obtained from 90,000 ratings of 986 movies by 692 users on Douban, and the ratings were integers within [1, 5], with a positive correlation between the rating and the user’s liking; i.e., a higher rating means that the user likes the movie more, while a lower rating means that the user likes the movie less. The specific parameters included in the experiment and the settings are shown in Table 2.Table 2
Parameter setting.
ParameterValueNeighborhood mean parameter10Number of cluster centers10Control parameterslimit100Maximum iteration times of clustering model20The improved collaborative filtering recommendation algorithm proposed in the study is based on the swarm K-means clustering model. The strength of the new fitness function directly affects the performance of the algorithm, so the traditional fitness function is compared with the new fitness function to test the performance of the improved algorithm. The clustering results of both under the same data set are shown in Figure4.Figure 4
Clustering results of old and new fitness functions in the same data set.
(a)
Traditional fitness function(b)
New fitness functionIn Figure4, the larger asterisks represent the cluster centers, and points of the same shape are in the same class. From Figure 4(a), it can be seen that the distance of sample points within the class center is smaller, which achieves better intraclass compactness, but the separation between classes does not perform significantly, while the clustering results in Figure 4(b) not only have better compactness but also better separation, indicating that the overall performance of the new fitness function is better than that of the traditional fitness function. The impact of both on the recommended results is shown in Table 3.Table 3
Comparison of MAE values between new and classical fitness functions.
Number of nearest neighborsFitnessnewFitnessclassical100.8450.825150.8180.815200.7750.833250.7450.803300.6930.800350.7300.750Average0.7670.804Winning times42As can be seen from Table3, the number of wins for the new fitness function and the traditional fitness function is 4 and 2, respectively, and the average MAE value forFitnessnew is 0.767 and 0.804 for Fitnessclassical, indicating that the new fitness function outperforms the traditional fitness function in terms of average value and number of wins. The results indicate that the new fitness function is able to improve the quality of recommendations. To further validate the performance of the improved swarm algorithm, four commonly used test functions, Griewank, Rastrigin, Sphere, and Rosenbrock, were tested. The characteristics of the four test functions are shown in Table 4.Table 4
Characteristics of four test functions of improved bee colony algorithm.
NameSearch intervalGlobal minimumRosenbrock[-100,100]0Griewank[-600,600]0Rastrigin[-100,100]0Sphere[-100,100]0In Table4, Rastrigin and Griewank have similar characteristics, both being multipeaked functions, Sphere is a multipeaked convex function, and Rosenbrock is a convex function with consecutive single peaks. The global minimum 0 is obtained atxi=0i=1,2,⋯,n for all four. The iterative trends in fitness between the original swarm algorithm and the improved algorithm on Rastrigin, Griewank, Rosenbrock, and Sphere are shown in Figure 5.Figure 5
Change of fitness iteration trend before and after improved bee colony algorithm.
(a)
Sphere(b)
Griewank(c)
Rosenbrock(d)
RastriginFrom Figures5(a) and 5(b), it can be seen that the iterative search for the optimal value of the original swarm algorithm has different degrees of slow convergence and local extremes in all four test functions; from Figures 5(d) and 5(c), it can be seen that the original artificial swarm algorithm requires a longer iteration time and more iterations to reach the same local optimal solution than the improved algorithm; and in Figure 5(d) and the fitness trend in Figure 5(b), the accuracy and precision of the original artificial bee colony algorithm in searching for the optimal solution is poor and differs from the improved bee colony algorithm in the optimal solution by multiple orders of magnitude. The initialization process of the improved algorithm is purposeful and introduces a global bootstrap factor, so its convergence speed and search accuracy are significantly higher than the original algorithm in the iterative search for the optimal solution. The improved swarm K-means algorithm was then tested for performance with the parameters set as shown in Table 5.Table 5
Parameter of improved ABC-K-means.
NameValueColony size20Number of clusters in Iris3Maximum iterations100Number of clusters in Balance-scale3Number of clusters in Glass6Maximum mining times10The number of datasets Iris, Balance-scale, and Glass was 150, 625, 625, and 214, respectively; the number of attributes was 4, 4, and 10, respectively; and the number of classifications was 3, 3, and 6, respectively. The convergence trends of the fitness values of the improved swarm K-means algorithm for 100 runs on the three datasets are shown in Figure6.Figure 6
Convergence trend of fitness values of improved bee colony K-means algorithm on three data sets.As can be seen in Figure6, on the Iris, Glass, and Balance-scale datasets, the magnitude of change in fitness of the improved swarm K-means algorithm is smaller over the course of the population iterations, and the new position update formula enables the algorithm to dynamically adjust the search step and gradually approximate towards the global optimum. The algorithm jumps out of the local optimum in 60 iterations on the Balance-scale dataset and reaches a position with a higher fitness value. Therefore, the algorithm is able to accurately obtain the global optimal solution in a shorter time with fewer iterations required, faster convergence, and higher stability for both the dataset Glass with a large attribute dimensionality and the dataset Balance-scale with a larger sample size. To verify the better recommendation quality of the collaborative filtering recommendation algorithm proposed in the study, it is compared with the user-based recommendation algorithm [26], the user-based clustering algorithm [27], and the ICCFRA algorithm [28]. Firstly, 560 users in the dataset were selected to form the training set and 321 to form the test set, and different numbers of nearest neighbors were set. The MAE results of the four recommendation algorithms are shown in Table 6.Table 6
Comparison of MAE results between the collaborative filtering recommendation algorithm based on bee colony K-means clustering and other three algorithms.
Number algorithmUser recommendation-based algorithmUser-based clustering algorithmICCFRAImproved collaborative filtering recommendation algorithm100.8660.8920.7920.844150.8220.8820.7820.818200.7860.8770.7640.777250.7670.8620.7620.747300.7620.8570.7610.695350.7610.8420.7620.732In Table6, “Number” represents the number of nearest neighbors. From Table 6, the MAE values of the algorithm proposed in the study are smaller than those of the user-based clustering algorithm and the user recommendation algorithm, and the MAE values of the ICCFRA algorithm gradually exceed the algorithm as the number of nearest neighbors increases. Therefore, the algorithm’s recommendation results are more reliable, and the accuracy of the algorithm is more reliable when the amount of data increases. To verify the running efficiency of this algorithm, the running time of the algorithm was compared with the other three algorithms, and the running time of all four is shown in Figure 7.Figure 7
Running time comparison between collaborative filtering recommendation algorithm based on bee colony K-means clustering and other algorithms.As can be seen from Figure7, the user-based recommendation algorithm takes significantly more time than the improved algorithm, with the highest at 150 seconds when the number of nearest neighbors is 30. The difference in running time between the collaborative filtering algorithm based on user clustering and the improved algorithm is smaller, with the highest time of the improved algorithm being 50 seconds. This is due to the fact that the improved algorithm first clusters users and then builds user clusters, largely reducing the space for searching nearest neighbors. It improves the quality of recommendations as well as ensures operational efficiency.


## 5. Conclusion

Collaborative filtering recommendation algorithm is the most widely used and successful recommendation algorithm in the recommendation system, but its recommendation efficiency and quality are low at present. Therefore, an improved bee colony K-means clustering model is established and applied to the collaborative filtering recommendation algorithm to optimize the recommendation system. The experimental results show that under the same data set, the MAE value of the new fitness function is 0.767 on average, while that of the traditional fitness function is 0.804. In the four commonly used test functions Rosenbrock, Griewank, Rastrigin, and Sphere, the improved algorithm can obtain the same local optimal solution in a shorter iteration time and fewer iterations. In the iterative optimization process, the improved algorithm has higher convergence speed and search accuracy than the original algorithm. The MAE value of user clustering algorithm and user recommendation algorithm is larger than that of the improved algorithm, and the accuracy of the algorithm is more reliable when the number of nearest neighbors increases. In terms of running time, the improved algorithm has a maximum time of 50 seconds and has higher running efficiency. However, the user data included in the study is still relatively small, and more abundant information data is needed to determine the number of nearest neighbors.



---

*Source: 2213173-2022-12-22.xml*