# Improved Honey Badger Algorithm and Its Application to K-Means Clustering
## 4 K-Means Algorithm Based on Improved Honey Badger Algorithm  
In this study, a K-means algorithm based on the Improved Honey Badger Algorithm (IHBA-KM) is proposed as a way to compensate for the lack of random selection of the center of mass in K-means. IHBA-KM uses the sin chaos method for population initialization, thereby increasing the randomness and diversity of initial clustering centers. By introducing an improved density factor, the algorithm can better adapt to different data distributions. In the process of position updating, nonlinear inertial weights are used to make the search process more balanced. In addition, the incorporation of random opposition-based learning significantly enhances the selection process for clustering centers. Next, this paper will describe the detailed steps of IHBA-KM:  
Step 1: Initialization parameters are set: data set \(S\), population number \(N\), maximum number of iterations \(t_{max}\), and cluster number \(K\);  
Step 2: \(K\) data points are selected randomly from the data set to serve as the positions of honey badgers. These data points will be used as candidate cluster centers in the initial stage, and initial locations will be assigned to honey badgers according to different dimensions. The process will be repeated N times, a total of N honey badger individuals will be generated, and then new locations of the honey badgers will be calculated according to Formula (8). Step 3: According to step 2, there are \(2N\) honey badger individuals, including the original solution and the chaotic solution. The data set is clustered, the fitness is assigned, and at the same time, the first \(N\) honey badgers are taken as the initial population. Step 4: The optimal individual and its fitness are discovered;  
Step 5: A random number \(r\) is generated. \(r\) is less than 0.5. The algorithm carries out a global search, uses Formula (11) to update the position, and carries out boundary processing;  
Figure 5: IHBA flowchart. The blue squares represent the parts of the paper that have been improved. Step 6: Otherwise, the algorithm carries out a local search, uses Formula (12) to update the position, and carries out boundary processing;  
Step 7: Clustering operations are performed after the location update, and the newly generated cluster center is set to the location updated in step 5 or 6;  
Step 8: The current optimal solution is updated, and then the opposition solution is calculated according to Formula (13). The fitness of the opposition solution is compared with the original global optimal solution. The solution with the least fitness is the global optimal solution, and the corresponding position is saved as the best position. Step 9: Step 5 and Step 6 are repeated until termination conditions are met;  
Step 10: Using the optimal solution as the cluster center, the distance from the data points to the clustering center is calculated and the data are assigned to the closest cluster. The optimal solution, location, and clustering results are output. To summarize the steps above, we provide the pseudo code of IHBA-KM, as shown in Algorithm 1. ```
Initialize the parameters of the algorithm: \(S,\ K,\ N,\ t_{max}\). Initialize population location at random positions. Initialization of the population using the sin chaos. Cluster data set. evaluate the fitness of every \(x_{i}\) and give it to \(f_{i}\). Save the best position \(x_{prey}\) and give its fitness \(f_{prey}\). while\(t\leq\)\(t_{max}\)do  Update the factor \(\alpha_{1}\) using Equation (9). for\(i=1\) to \(N\)do  Calculate the intensity I using Equation (2). if\(r<0.5\)then  Update the new position using Equation (11). else  Update the new position using Equation (12). endif  Execute clustering. Evaluate the new position and assign to fitness. Calculate the random reverse solution \(x_{ROBL}\) using Equation (13) and assign to \(f_{ROBL}\).