# A Dynamic Density Peak Clustering Algorithm Based on K-Nearest Neighbor

Authors: Hui Du; Qiaofeng Zhai; Zhihe Wang; Yongbiao Li; Manjie Zhang
Journal: Security and Communication Networks
 (2022)

---

## Abstract

The clustering results of the density peak clustering algorithm (DPC) are greatly affected by the parameterdc, and the clustering center needs to be selected manually. To solve these problems, this paper proposes a low parameter sensitivity dynamic density peak clustering algorithm based on K-Nearest Neighbor (DDPC), and the clustering label is allocated adaptively by analyzing the distribution of K-Nearest Neighbors around each data. It reduces the parameter sensitivity and eliminates selecting the clustering centers manually from the decision graph. Through the experimental analysis and comparison of the artificial dataset and UCI dataset, the results show that the comprehensive clustering effect of DDPC is better than DPC, DBSCAN, DBC, and other algorithms.


---

## Body

## 1. Introduction

In recent years, data mining technology has become the main means to process a large amount of data and convert it into useful information. It is also a hot issue in artificial intelligence research [1, 2]. At present, it has been applied in many fields, including retail, recommendation, biological information, market analysis, and so on. Clustering is a common unsupervised learning method in the field of data mining [3]. It is also a research tool in the fields of computer vision and image segmentation. The purpose of the clustering algorithm is to divide the data into different clusters according to a certain feature or law [4]. The data with high similarity will be assigned to the same cluster, and the regions with low similarity will be assigned to different clusters [5]. Clustering algorithm also has many applications in the fields of computer science, mathematics, and the Internet of things [6, 7]. Taking wireless sensor as an example, the node distribution of wireless sensor is usually dense, and there is redundancy in the information transmission between nodes [8]. The clustering algorithm is used to cluster and process the sensor node data of different clusters to reduce the impact of information redundancy.At present, the widely used basic clustering algorithms include the k-means algorithm [9], hierarchical clustering [10], density algorithm [11], and so on. K-means algorithm is the most classical clustering method. Through the random clustering center, the cluster allocation results and clustering center are iteratively optimized until the clustering center is no longer changed. Although the algorithm has a good effect on convex datasets [12], its limitation is that it is easy to fall into local optimization. The method of hierarchical clustering is to calculate the similarity [13, 14] between each node and other nodes at first and then merge the nodes one by one according to the similarity from high to low until the expected number of clusters is reached. DPC is a new density clustering algorithm. It determines the density of a single node by calculating the number of data in a certain range, selects the clustering center according to the density and data spacing, and assigns each low-density point to the nearest high-density point to realize clustering. DPC can get good clustering results not only on convex datasets but also on nonconvex datasets. However, the disadvantage is that it is greatly affected by the parameters [15]. It is hard to select the appropriate clustering center [16]. DPC cannot achieve good clustering results for clustering regions with discontinuous density [17]. Fast density peak clustering for large-scale data based on KNN [18] greatly reduces the complexity of determining local density peaks.In recent years, there are many improvements for the DPC algorithm, which are mainly divided into the following aspects: in terms of clustering mode, a novel clustering algorithm based on directional propagation of cluster labels (DBC) [19] was proposed at the International Joint Conference of Neural Networks. DBC is a direction-based clustering method. By introducing the concepts of direction and angle, the clustering process is optimized, and the final clustering effect is better than that of DPC. However, the shortcoming of this algorithm is that it has many parameters and high sensitivity. In terms of formula improvement, an improvement of density peak clustering algorithm based on KNN and gravity [20] puts forward a new density formula, which makes the local density of sample points in dense and sparse areas more separable. In terms of centroid selection, a density peak clustering algorithm [21] based on feasible residual error was proposed, which realized semiautomatic clustering recognition and improved the iterative process of centroid selection of DPC. In 2021, a density peak clustering algorithm based on density decay graph [22] was proposed. The algorithm overcomes the shortcomings of the DPC algorithm, which needs to manually select the cluster center, and is greatly affected by chain reaction. The clustering process is realized by introducing a density decay graph. Although the clustering effect of this algorithm is better than that of DPC and other algorithms, there is no way to adjust the parameters dynamically according to the regional density, which is greatly limited by the parameters, and additional parameters are added based on the parameters of DPC algorithm. Even if the final clustering effect is good, the adjustment cost is high. In terms of algorithm combination, the proposed KNN-HDPC algorithm [23] makes the combination of KNN and DPC possible. In addition, the density peak clustering based on improved mutual K-Nearest Neighbor graph [24] solves the problem of poor clustering effect when different density regions are adjacent in DPC. In terms of noise point treatment, a novel density peak clustering algorithm based on squared residual error proposed by Parmar et al. [25] can help DPC solve the problem of noise point detection.Through the analysis of clustering-related algorithms in recent years, most density clustering algorithms are based on the improvement of DPC, including accuracy improvement, algorithm combination, noise data processing, and so on. The main defects of the current algorithms are that it is hard to obtain the ideal cluster centers, the clustering process is complex, the requirements for parameter sensitivity are high, and the clustering effect on some real datasets is not ideal. In the future, reducing the parameter sensitivity of the clustering algorithm is a research direction.The main contribution of this paper is to propose a dynamic density peak clustering algorithm based on K-Nearest Neighbor (DDPC) that can reduce the parameter sensitivity and choose cluster centers automatically. The calculation accuracy of DDPC is higher than that of the DPC algorithm. DDPC calculates the local density through the KNN distribution of each data and then divides each data into high-density data and low-density data according to the local density. For high-density data, the scanning distance is calculated according to the average distance of K-Nearest Neighbors. Using the feature that the scanning distance is self-adaptive with the regional density, the two mutually scanned data are classified into a cluster to reduce the sensitivity of parameters. For low-density data, after clustering high-density data, KNN method is used for clustering. We used NMI, ARI, Homogeneity (Homo), andF1 as the evaluation indexes in the experiment. The experimental results show that compared with the DPC algorithm, the performance evaluation index NMI of DDPC is improved by 0.23 on average. ARI increased by 0.24 on average, homogeneity increased by 0.21 on average, and F1 score increased by 0.19 on average.


## 2. Related Works

### 2.1. DPC

DPC is a density clustering algorithm that can remove noise points. It was presented in Science in 2014. At the same time, the clustering effect of the DPC is stable and will not be affected by randomness like the k-means. The core of the DPC mainly involves the following two points: (1) The density of cluster centers is the largest in clustering; (2) the distance between the highest density points in local areas is often large. Therefore, the DPC needs to first calculate the density valueρi of each data point xi, which is determined by the dataset and truncation distance. Then calculate the distance δi between each data and its nearest higher density point according to the density value.Definition 1.
Local density: The local densityρi of data point xi is calculated as follows:
For a given datasetX=x1,x2,…,xn, there are two ways to calculate the local density ρi: truncation function and Gaussian kernel function. The specific calculation methods are described below.
The truncation function is used to calculateρi, and the calculation method is shown in the following formulas:(1)ρi=∑jNAdij−dc,(2)Ax=0,x<0,1,x⩾0,where dc>0 is the truncation distance, and the Euclidean distance between xi and xj is expressed as dij. The recommended truncation distance is 1%−2% of the distance between all data points [11]. A(x) is the truncation function. The value of the truncation function is determined by X. The value is 1 when x<0 and 0 when x⩾0. Therefore, the local density ρi represents the number of other data in the dc range around data xi.
Use Gaussian kernel function to calculateρi, see formula asfollows:(3)ρi=∑jNe−dij/dc2.
Among them,dij and dc have the same meaning as in Definition 1. The Gaussian kernel function is more suitable for the case of a small amount of data because it only produces a small probability conflict, which is not applicable when the amount of data is large.Definition 2.
Delta: The distanceδi from the data point xi to the high-density point xj is calculated asfollows:(4)δi=maxj:ρi>ρjdij,minj:ρj>ρidij..
According to the above formula, for a data pointxi, if its density is the maximum value, its corresponding δi is the farthest distance between it and other data points. Otherwise, δi is the distance between the data point xi and the nearest higher density data point.
Therefore, for data points not in the cluster center, theδi will be small, on the contrary, the δi in the cluster center will be large. In particular, it should be noted that some data have a large δi, but the ρi is small, which indicates that there are little data around the data and are far from the cluster center. We identify such data as outliers. In cluster allocation, the cluster labels of noncentral points will be consistent with the cluster labels of the nearest higher density points.


### 2.2. KNN

K-Nearest Neighbor clustering [26] is a simple clustering algorithm. According to the previously entered parameter K, traverse its K-Nearest Neighbor cluster tag and assign the data to the cluster with the most cluster tags in the K-Nearest Neighbor of the data, and so on until all the data are assigned to the cluster tag.The algorithm of K-Nearest Neighbor is as Algorithm1.Algorithm 1: KNN Algorithm.
Input: Dataset D = x1,x2,x3,…,xn, K, Some tagged data C = c1,c2,c3,…,ctOutput: Clusters = {c1, c2,…,ct}//Loop to get the firstk nearest neighbors of each data and sort them.for each data point x in Ddofor each data point y in DdoCalculate the distance betweenx and yend forSort the data according to the distance from small to large:Nx = n1,n2,n3,…,nktarget=maxc∈Cc∩Nxfor each c in Cdomark=cj∩Nxifmark==targetthenx∈cjend ifend forend for


### 2.3. Local Density Peak

To prevent the influence of density discontinuous data, we need to obtain the local density peak [27] in the regions where the data with different densities are located. In this way, even if all the densities in some regions are low, high-density points will still be generated for subsequent clustering [28]. We determine whether each data should be viewed as a high-density point by judging the density relationship between each data and its K adjacent data. Two parameters need to be introduced, one is the parameter K to determine the number of neighbors and the other is the ratio parameter R to determine whether it should be used as a high-density point. The local density peak in this region can be calculated by these two parameters.Definition 3.
KNN density: KNN densityρi of data point xi is calculated as follows:
For a given datasetX=x1,x2,…,xn, where the K-Nearest Neighbor of point xi is expressed as N=x1,x2,…,xk. When calculating the local density ρi of xi, the average distance between its K-Nearest Neighbor is calculated. The larger the average distance is, the lower the point density is. On the contrary, the higher the point density is. The distance measurement here adopts Euclidean distance, which is more convenient for subsequent understanding. Here, the reciprocal of the calculation result is taken to make the result consistent with the corresponding relationship between the density. For details, see the following formula:(5)ρi=k∑jkxi−Nj2,where ρi represents the local density of xi, Nj represents the jth neighbor of the xi, that is, the jth nearest neighbor, and K is a parameter used to represent the number of neighbors for each data search. Generally speaking, averaging the distance between each neighbor and the point can reflect the density of the point relative to the K points around the circumference. Therefore, the smaller the calculated average distance, the higher the density of the point. To make the result proportional to the density, it is expressed by the reciprocal.
By comparing the local densityρi of the xi and its K-Nearest Neighbor, combined with the ratio parameter R, calculate whether xi is a high-density point.
For a given data pointxi, compare its density with the surrounding neighbors through the ρi of the point and the local density P=ρ1,ρ2,…,ρk of its K neighbors, count the number of all local densities in the neighbors that are higher than the data, calculate a ratio with parameter K, and compare the ratio with ratio parameter R. If it is higher than ratio parameter R, the data are determined as a high-density point. First, it is necessary to compare the density between the point and each neighbor. For details, see the following formula:(6)lj=0,ρi>Pj1,ρi≤Pj,where lj represents the density comparison result between the point and its jth neighbor, and P is the density set of K neighbors of the data. See the following equation for the judgment of subsequent high-density points:(7)xi∈C,∑jkljk>R,xi∈L,∑jkljk⩽R,where C is the high-density point set, L is the non-high-density point set, and R is the ratio parameter. It is not difficult to see from the formula that the relative size of the local density peak is determined by the size of R. If the ratio of the number of neighborhoods below the point density to K is greater than the ratio parameter R, the point is defined as a high-density point; otherwise, it is a low-density point. After all high-density points are distinguished through the above calculation process, the area composed of high-density points is called a high-density area, which is also a local density peak. Figure 1 is a schematic diagram of local density peaks on a hard dataset, in which red data points are high-density areas, and black data points are low-density areas.Figure 1
Local density peak on hard dataset.


## 2.1. DPC

DPC is a density clustering algorithm that can remove noise points. It was presented in Science in 2014. At the same time, the clustering effect of the DPC is stable and will not be affected by randomness like the k-means. The core of the DPC mainly involves the following two points: (1) The density of cluster centers is the largest in clustering; (2) the distance between the highest density points in local areas is often large. Therefore, the DPC needs to first calculate the density valueρi of each data point xi, which is determined by the dataset and truncation distance. Then calculate the distance δi between each data and its nearest higher density point according to the density value.Definition 1.
Local density: The local densityρi of data point xi is calculated as follows:
For a given datasetX=x1,x2,…,xn, there are two ways to calculate the local density ρi: truncation function and Gaussian kernel function. The specific calculation methods are described below.
The truncation function is used to calculateρi, and the calculation method is shown in the following formulas:(1)ρi=∑jNAdij−dc,(2)Ax=0,x<0,1,x⩾0,where dc>0 is the truncation distance, and the Euclidean distance between xi and xj is expressed as dij. The recommended truncation distance is 1%−2% of the distance between all data points [11]. A(x) is the truncation function. The value of the truncation function is determined by X. The value is 1 when x<0 and 0 when x⩾0. Therefore, the local density ρi represents the number of other data in the dc range around data xi.
Use Gaussian kernel function to calculateρi, see formula asfollows:(3)ρi=∑jNe−dij/dc2.
Among them,dij and dc have the same meaning as in Definition 1. The Gaussian kernel function is more suitable for the case of a small amount of data because it only produces a small probability conflict, which is not applicable when the amount of data is large.Definition 2.
Delta: The distanceδi from the data point xi to the high-density point xj is calculated asfollows:(4)δi=maxj:ρi>ρjdij,minj:ρj>ρidij..
According to the above formula, for a data pointxi, if its density is the maximum value, its corresponding δi is the farthest distance between it and other data points. Otherwise, δi is the distance between the data point xi and the nearest higher density data point.
Therefore, for data points not in the cluster center, theδi will be small, on the contrary, the δi in the cluster center will be large. In particular, it should be noted that some data have a large δi, but the ρi is small, which indicates that there are little data around the data and are far from the cluster center. We identify such data as outliers. In cluster allocation, the cluster labels of noncentral points will be consistent with the cluster labels of the nearest higher density points.


## 2.2. KNN

K-Nearest Neighbor clustering [26] is a simple clustering algorithm. According to the previously entered parameter K, traverse its K-Nearest Neighbor cluster tag and assign the data to the cluster with the most cluster tags in the K-Nearest Neighbor of the data, and so on until all the data are assigned to the cluster tag.The algorithm of K-Nearest Neighbor is as Algorithm1.Algorithm 1: KNN Algorithm.
Input: Dataset D = x1,x2,x3,…,xn, K, Some tagged data C = c1,c2,c3,…,ctOutput: Clusters = {c1, c2,…,ct}//Loop to get the firstk nearest neighbors of each data and sort them.for each data point x in Ddofor each data point y in DdoCalculate the distance betweenx and yend forSort the data according to the distance from small to large:Nx = n1,n2,n3,…,nktarget=maxc∈Cc∩Nxfor each c in Cdomark=cj∩Nxifmark==targetthenx∈cjend ifend forend for


## 2.3. Local Density Peak

To prevent the influence of density discontinuous data, we need to obtain the local density peak [27] in the regions where the data with different densities are located. In this way, even if all the densities in some regions are low, high-density points will still be generated for subsequent clustering [28]. We determine whether each data should be viewed as a high-density point by judging the density relationship between each data and its K adjacent data. Two parameters need to be introduced, one is the parameter K to determine the number of neighbors and the other is the ratio parameter R to determine whether it should be used as a high-density point. The local density peak in this region can be calculated by these two parameters.Definition 3.
KNN density: KNN densityρi of data point xi is calculated as follows:
For a given datasetX=x1,x2,…,xn, where the K-Nearest Neighbor of point xi is expressed as N=x1,x2,…,xk. When calculating the local density ρi of xi, the average distance between its K-Nearest Neighbor is calculated. The larger the average distance is, the lower the point density is. On the contrary, the higher the point density is. The distance measurement here adopts Euclidean distance, which is more convenient for subsequent understanding. Here, the reciprocal of the calculation result is taken to make the result consistent with the corresponding relationship between the density. For details, see the following formula:(5)ρi=k∑jkxi−Nj2,where ρi represents the local density of xi, Nj represents the jth neighbor of the xi, that is, the jth nearest neighbor, and K is a parameter used to represent the number of neighbors for each data search. Generally speaking, averaging the distance between each neighbor and the point can reflect the density of the point relative to the K points around the circumference. Therefore, the smaller the calculated average distance, the higher the density of the point. To make the result proportional to the density, it is expressed by the reciprocal.
By comparing the local densityρi of the xi and its K-Nearest Neighbor, combined with the ratio parameter R, calculate whether xi is a high-density point.
For a given data pointxi, compare its density with the surrounding neighbors through the ρi of the point and the local density P=ρ1,ρ2,…,ρk of its K neighbors, count the number of all local densities in the neighbors that are higher than the data, calculate a ratio with parameter K, and compare the ratio with ratio parameter R. If it is higher than ratio parameter R, the data are determined as a high-density point. First, it is necessary to compare the density between the point and each neighbor. For details, see the following formula:(6)lj=0,ρi>Pj1,ρi≤Pj,where lj represents the density comparison result between the point and its jth neighbor, and P is the density set of K neighbors of the data. See the following equation for the judgment of subsequent high-density points:(7)xi∈C,∑jkljk>R,xi∈L,∑jkljk⩽R,where C is the high-density point set, L is the non-high-density point set, and R is the ratio parameter. It is not difficult to see from the formula that the relative size of the local density peak is determined by the size of R. If the ratio of the number of neighborhoods below the point density to K is greater than the ratio parameter R, the point is defined as a high-density point; otherwise, it is a low-density point. After all high-density points are distinguished through the above calculation process, the area composed of high-density points is called a high-density area, which is also a local density peak. Figure 1 is a schematic diagram of local density peaks on a hard dataset, in which red data points are high-density areas, and black data points are low-density areas.Figure 1
Local density peak on hard dataset.


## 3. DDPC

DDPC algorithm first obtains the high-density region of the dataset through the local density peak and then clusters the high-density region by dynamically adjusting the scanning distance by judging the density of each high-density region module. After the division of high-density regions is completed, the final division of low-density regions is realized by the KNN algorithm combined with cluster labels. The algorithm has two parameters: proximity parameterK and ratio parameter R. The size of K determines the number of neighbors of a single data point. The larger the K is, the more neighbors of each data, and the density distribution around each data becomes clearer. The clustering effect is more ideal for large-scale datasets, but it will increase the amount of calculation. The value of K should not be greater than the number of data in a cluster, which will cause unnecessary interaction between data in different clusters. The ratio parameter R determines the size of local density peak. The value range of R is [0, 1]. The larger the R is, the smaller the proportion of high-density regions; the distribution of high-density regions will be more discrete, and the number of clusters will be more. The smaller the R is, the larger the proportion of high-density regions is; the high-density regions tend to be a whole, and the number of clusters will be less.First, we need to obtain the high-density region through the local density peak. Because the local density is adopted after obtaining the high-density regions, the average density difference between different high-density regions may be large. By using local density to dynamically adjust the scanning distance, the influence of density difference can be reduced.The main step of clustering is to calculate the scanning distance. Only high-density points have the scanning distance, and the purpose of calculating the scanning distance is to dynamically adjust the clustering range according to the surrounding density. The specific calculation method is to calculate the average distance between the point and itsK neighbors and take the distance as the scanning distance. The scanning distance of high-density points in high-density areas is short, and the scanning distance of high-density points in low-density areas is long.Definition 4.
Each high-density point has its own scanning distance, which is defined as follows:(8)si=∑jkxi−Nj2k.
Similar to formula (5), Nj represents the jth neighbor of the data point xi. The scanning distance of xi will change dynamically according to the density distribution of its K neighbors. Through the formula, we know that the scanning distance calculation method is the average Euclidean distance between the xi and its K-Nearest Neighbors, that is, when the xi is in the high-density region, the average distance between its K-Nearest Neighbors and the xi is small, and the scanning distance is short. When the xi is in the low-density area, the average distance between the K-Nearest Neighbor and the xi is large, and the scanning distance is long. From Figure 2, we can observe the scanning distance of high-density area and low-density area when K is 14 (Algorithm 2).
After obtaining the scanning distance of each high-density point, carry out density transfer clustering according to the scanning distance of each high-density point. First, randomly select a high-density point without a cluster label, classify other high-density points within the scanning distance of the high-density point into a cluster, and scan the high-density points without a cluster label within the scanning distance of these high-density points. It is also classified as a cluster. All high-density points in the cluster are scanned until no new high-density points without cluster marks are found. Then, a new high-density point without a cluster label is randomly selected as a new cluster, and the above process is repeated until all high-density points have cluster labels.
Because the high-density points are often inside the cluster, and the scanning distance of each high-density point is strictly limited by its surrounding density, it is difficult for the high-density points between different clusters to be scanned through the scanning distance and merged into a cluster. This has the advantage that the clustering range will change dynamically with the internal density of the cluster, which effectively solves the problem of clustering in areas with discontinuous density; at the same time, different clusters will not be merged into one class. Another purpose of dynamic density peak clustering is to find the high-density regions of each cluster and cluster them to prepare for the final K-neighbor clustering.
The main defects of the current algorithm are two aspects: first, the data density distribution has a great impact on the calculation time of the adaptive algorithm. Second, for high-dimensional and large-scale data, the computational efficiency of the algorithm is not high. In the future, based on maintaining the existing accuracy, we will invest more energy to improve the calculation efficiency and reduce the calculation time of high-dimensional and large-scale data. It will take a lot of time, but I am confident.
Since the high-density points have been assigned cluster labels before, the cluster labels of these high-density points are also applied to K-Nearest Neighbor clustering as the clustering basis of low-density points. The clustering target of K-Nearest Neighbor clustering is low-density points. After a sufficient iterative process, all low-density points are also assigned cluster markers. So far, all data are assigned cluster markers. The pseudocode of the algorithm is shown in Figure3. In the pseudocode, Nx is the sorted neighbor set, S is the average distance set of K-Nearest Neighbors, H is the high-density point set, and Ct is the unlabeled point set.Figure 2
Scanning distance map.Algorithm 2: DDPC Algorithm.
Input: Dataset D = x1,x2,x3,…,xn, K,ROutput: Clusters = {c1, c2,…,ct}//Calculate the local density of each data.for each data point x in Ddofor each data point y in DdoCalculate the distance betweenx and yend forSort the firstK data according to the distance from small to large: Nx = n1,n2,n3,…,nkCalculate the average distancelx from each neighbor Nxend forThe average distance matrix ofK neighbors of each node (scanning distance) is obtained: S = s1,s2,…,sn//The adaptive adjustment range is determined according to parametersK//and R.for each x in DdoCalculate the number of neighbors whose average distance is smaller than the node:mifm>1−R∗Kthenx is a high-density point: x∈Hend ifend forIntt = 1//Adaptive clusteringfor each x in HdoIfx has no cluster label thenx∈ctend iffor each y in Hdofor each z in ctdoif the distance between y and z is less than sy or szthenIfy has cluster label thenChange ally’s cluster labels to ctelsey∈ctend ifbreakend ifend forend fort++end forFor the points without cluster label, KNN algorithm is used for clusteringFigure 3
Flow chart of DDPC.


## 4. Experiments

Taking the clustering evaluation index as the standard, we test the proposed algorithm on the artificial dataset and UCI dataset, respectively. The comparison algorithms include the k-means algorithm, DBSCAN algorithm, DPC algorithm, and DDPC algorithm. The datasets adopt artificial datasets and real datasets. Artificial datasets include 2d-3c, threecircles, etc.; UCI datasets include vote, WDBC [29], zoo [30], vowel, seeds, ecoli [31], banknote, etc.In this paper, all experimental parameters are selected by cyclic parameter adjustment, and the best result of NMI performance is retained as the final experimental result. Among the comparison algorithms selected in this paper, only the k-means algorithm is the meta-heuristic method. We have carried out 10 experiments on the same dataset and used the average value of the evaluation index as the experimental results of the K-means algorithm.The evaluation indexes of clustering are Adjusted Rand Index (ARI), Normalized Mutual Information (NMI), Homogeneity Index (Homo), andF-Scores (F1). ARI is an adjusted RI, which has higher discrimination than RI. The value range of ARI is [−1, 1]. The closer the value is to 1, the better the clustering result is, and the closer it is to 0, the worse the clustering result is. The calculation formulas of RI and ARI are as follows:(9)RI=a+bn2,(10)ARI=RI−ERImaxRI−ERI,where C represents the actual classification, and K represents the clustering results. a is defined as the number of instance pairs divided into the same class in C and the same cluster in K. b is defined as the number of instance pairs divided into different categories in C and different clusters in K. For formula (9), n represents the total number of clusters, n2=Cn2=nn−1/2. Obviously, the value range of RI is [0, 1]. The larger the value, the better the clustering effect. For equation (10), max represents the maximum value and E represents the expectation.NMI is an external indicator that measures the clustering effect by comparing the clustering results with “real” class labels; the value range of NMI is [0, 1]. The larger the value, the better the clustering effect.(11)NMI=∑i=1kC∑j=1kTni,jlogn∗ni,j/ni∗nj∑i=1kCnilogni/n∑j=1kTnjlognj/n,where K(C) is the number of clusters in the clustering result, K(T) is the number of clusters in the real clustering result, ni is the number of samples in cluster i, nj is the number of samples in cluster j, ni,j is the number of samples between the samples belonging to cluster i in the clustering result C and the samples belonging to cluster j in the real clustering result T, and n is the total number of samples in the dataset.The value of homogeneity depends on the degree to which each cluster contains only members of a single class; the value range of homogeneity is [0, 1]. The larger the value, the better the clustering effect. Its calculation formula is asfollows:(12)Homogeneity=1−HC|KHC,(13)HC|K=−∑c=1C∑k=1Knc,kn∗lognc,kn,(14)HC=−∑c=1Cncn∗logncn,where n is the total number of samples, nc and nk are the number of samples belonging to class C and class K, respectively, and nc,k is the number of samples divided from class C to class K.As a comprehensive index,F-scores are to balance the impact of accuracy, recall, and comprehensively evaluate a classifier; the value range of homogeneity is [0, 1]. The larger the value, the better the clustering effect. Its formula is as follows:(15)F1=2TP2TP+FP+FN.TP refers to the data that determine the attribution, and the actual attribution is exactly the same; FP refers to the data that determine the attribution and does not belong, and FN refers to the data that determine the nonattribution but does belong.


### 4.1. Artificial Dataset

We use k-means, DPC, and DBSCAN algorithms as comparison objects, respectively. Figures4–7 show the clustering effect of each algorithm on 2d-3c dataset, grid.orig dataset, Jain dataset, and threecircles dataset, respectively. Due to space constraints, the corresponding evaluation indicators of the other six datasets are shown in Table 1. Experiments show that DDPC algorithm performs well on all datasets and is better than DPC algorithm. The details of the dataset are shown in Table 2.Figure 4
Clustering results on dataset 2d-3c. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Figure 5
Clustering results on dataset grid.orig. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Figure 6
Clustering results on dataset Jain. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Figure 7
Clustering results on dataset threecircles. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Table 1
Evaluation index of four algorithms on artificial datasets.
DatasetAlgorithmARINMIHomoF12d-3ck-means0.5898 ± 0.130.5733 ± 0.120.6056 ± 0.090.6619 ± 0.13DPC0.83090.81780.95620.9217DBSCAN0.81470.77530.74100.8328DDPC0.88200.85780.90070.9236grid.origk-means0.7601 ± 0.060.7164 ± 0.040.7121 ± 0.030.7367 ± 0.08DPC0.19880.30590.35260.3626DBSCAN0.98400.96630.96630.9915DDPC1.01.01.01.0Jaink-means0.4527 ± 0.090.3900 ± 0.070.4223 ± 0.080.4618 ± 0.11DPC1.01.01.01.0DBSCAN0.92620.82410.96900.9329DDPC1.01.01.01.0Threecirclesk-means0.0261 ± 0.020.1214 ± 0.010.1082 ± 0.030.1339 ± 0.02DPC0.09640.22730.35410.2846DBSCAN1.01.01.01.0DDPC1.01.01.01.0Flamek-means0.7323 ± 0.030.7154 ± 0.060.6987 ± 0.040.7432 ± 0.05DPC1.01.01.01.0DBSCAN0.98650.98650.99990.9873DDPC1.01.01.01.0Spiralk-means0.0164 ± 0.010.0321 ± 0.010.0289 ± 0.020.0236 ± 0.01DPC1.01.01.01.0DBSCAN1.01.01.01.0DDPC1.01.01.01.0Aggregationk-means0.7615 ± 0.030.7344 ± 0.020.7618 ± 0.060.7742 ± 0.05DPC1.01.01.01.0DBSCAN0.72210.73680.76390.8234DDPC0.99480.99150.99230.9974Lineblobsk-means0.5293 ± 0.080.6135 ± 0.110.6177 ± 0.070.6210 ± 0.12DPC0.64490.69330.68600.7128DBSCAN1.01.01.01.0DDPC1.01.01.01.0R15k-means0.8556 ± 0.030.8259 ± 0.030.8814 ± 0.010.8765 ± 0.02DPC0.97150.98330.97820.9867DBSCAN0.93640.92690.95160.9398DDPC0.98910.99130.99130.9950Sspiralk-means0.0237 ± 0.020.0231 ± 0.010.0216 ± 0.010.0253 ± 0.01DPC1.01.01.01.0DBSCAN1.01.01.01.0DDPC1.01.01.01.0Table 2
Artificial dataset.
DatasetInstanceDimensionCluster2d-3c71523Grid125022Jain37322Threecircles29923Flame21922Spiral31223Aggregation78827Lineblobs26623R15600215Sspiral94422Experimental results show that the DDPC algorithm proposed in this paper can achieve good clustering results on various difficult datasets in different density regions. At the same time, the DDPC algorithm can also achieve good clustering results for some nonconvex datasets. It can be seen from Figures4 and 5 that due to the limitation of parameters in other algorithms, a single parameter cannot solve the clustering problem of different density regions, resulting in a poor clustering effect. In Figure 6, the DBSCAN algorithm falls into local optimization and cannot cluster accurately. In Figure 7, because the density relationship of the dataset does not increase significantly, the DPC algorithm cannot cluster correctly due to the limitation of the density increasing condition. K-means algorithm cannot achieve a good clustering effect on nonconvex datasets. Therefore, it can be seen that the DDPC algorithm can achieve satisfactory clustering results whether it is a dataset with uneven density distribution or a nonconvex dataset, which cannot be done by other comparison algorithms.In terms of parameter sensitivity, DPC and DDPC are tested on the flame dataset. To accurately test the sensitivity of each parameter, based on the ARI evaluation index, we set one of the parameters as the ideal value and analyze the sensitivity of the parameter by observing the impact of the changes of other parameters on the clustering effect. The experimental results are shown in Figure8 and Tables 3–6. The observation results show that DDPC is superior to DPC in parameter sensitivity.Figure 8
Experimental results of parameter sensitivity on flame dataset. (a) DPC, (b) DPC, (c) DDPC, (d) DDPC.
(a)(b)(c)(d)Table 3
Experimental results of DPC on flame dataset whenK is optimal.
Dc0.10.20.30.40.50.60.70.80.91.0ARI0.291.00.960.010.010.010.010.00.010.01Table 4
Experimental results of DPC on flame dataset when dc is optimal.
K1234567ARI01.00.980.880.760.680.62Table 5
Experimental results of DDPC on flame dataset whenK is optimal.
R0.00.10.20.30.40.50.60.70.80.9ARI1.01.01.01.01.01.01.00.961.01.0Table 6
Experimental results of DDPC on flame dataset whenR is optimal.
K5101520253035ARI0.981.01.01.01.01.01.0


### 4.2. UCI Dataset

DDPC algorithm shows better clustering results on artificial datasets. To further verify its clustering performance, it also needs to be verified on the real datasets. Considering that the k-means algorithm has been proposed for a long time, this paper uses DBC (a novel clustering algorithm based on directional propagation of cluster labels) algorithm instead of K-means algorithm to compare on UCI dataset. After comparison, the comprehensive experimental results on a variety of different UCI datasets are better than DBC and other algorithms. UCI datasets are shown in Table7.Table 7
UCI datasets.
DatasetInstanceDimensionClusterVote435162WDBC569302Vowel87136Zoo101167Seeds21073Ecoli33678Banknote137242Dermatology358346Segment2310187Pendigits109921610In the UCI datasets, because it is difficult to visualize a high-dimensional dataset; the clustering evaluation indexes ARI, NMI, and homogeneity are compared. Table8 shows the evaluation indexes of each clustering algorithm. Although in the vowel dataset, the ARI of the DPC algorithm is slightly higher than that of the DDPC algorithm, and in the banknote dataset, the NMI of the DPC algorithm is slightly higher than that of the DDPC algorithm. However, in general, DDPC performs significantly better than other clustering algorithms on UCI datasets, and the clustering effect is the best. The second is the DBC algorithm and DPC algorithm. The clustering effect of the DBSCAN algorithm on the UCI dataset is the least ideal.Table 8
Evaluation index of four algorithms on UCI datasets.
DatasetAlgorithmARINMIHomoF1VoteDBSCAN0.44800.39770.50340.6106DPC0.00360.00310.02700.0107DBC0.57090.49420.50300.5236DDPC0.58500.52100.51160.8827WDBCDBSCAN0.46610.37900.38680.5131DPC0.48690.50280.51120.6628DBC0.58830.52580.66560.5669DDPC0.76680.68220.69970.9384VowelDBSCAN0.41700.53170.49020.4913DPC0.52310.59770.62850.6199DBC0.42210.55760.52420.4219DDPC0.51020.61560.65370.4948ZooDBSCAN0.14570.61610.62850.5266DPC0.30560.42220.32640.6953DBC0.88010.85450.76960.8752DDPC0.89180.86210.92750.8811SeedsDBSCAN0.00090.34260.42390.6137DPC0.76360.72190.71690.9127DBC0.78690.73980.73970.8623DDPC0.79160.77840.78190.9238EcoliDBSCAN0.14590.61610.62850.4523DPC0.45160.54020.72980.6404DBC0.71650.65710.55800.7653DDPC0.73980.70670.77050.8065BanknoteDBSCAN0.07520.29580.00560.1134DPC0.89350.93160.87610.9516DBC0.82980.74670.74270.8819DDPC0.95380.90990.90910.9883DermatologyDBSCAN0.41510.62050.64840.5761DPC0.42690.33040.41050.4429DBC0.78710.84860.78790.8626DDPC0.84590.90820.97030.6675SegmentDBSCAN0.24460.55250.42350.4695DPC0.24020.52620.40100.4968DBC0.36260.61090.62600.6371DDPC0.49650.65760.81440.7032PendigitsDBSCAN0.41510.62050.64840.5753DPC0.55420.72430.69380.7289DBC0.58180.66170.67040.7143DDPC0.63280.77750.96180.7695For DDPC, each data determine that the time complexity of the surroundingK neighbors is On2, the time complexity of calculating the local density and scanning distance is On, the time complexity of adaptive clustering is On∗k, and the overall time complexity of synthesizing the above information is On2. The time complexity of other algorithms compared in the experimental part is shown in Table 9.Table 9
Time complexity of each algorithm.
AlgorithmTime complexityk-meansOn∗k∗tDPCOn2DBSCANOn2DBCOn2DDPCOn2


### 4.3. Application

Wireless sensors are widely used in the Internet of things. The three functions of data acquisition, processing, and transmission are realized through a sensor network. Due to the large number and complex distribution of nodes in sensor networks, clustering can reduce the cost of information transmission between nodes. At the same time, some clustering algorithms can also eliminate the influence of noise data and improve experimental accuracy. Figure9 shows the difference in clustering accuracy between the DDPC algorithm and other clustering algorithms in the wireless sensor network dataset. The higher the clustering accuracy, the smaller the difference from the actual situation and the better the effect.Figure 9
Clustering results on dataset d1p07m.


## 4.1. Artificial Dataset

We use k-means, DPC, and DBSCAN algorithms as comparison objects, respectively. Figures4–7 show the clustering effect of each algorithm on 2d-3c dataset, grid.orig dataset, Jain dataset, and threecircles dataset, respectively. Due to space constraints, the corresponding evaluation indicators of the other six datasets are shown in Table 1. Experiments show that DDPC algorithm performs well on all datasets and is better than DPC algorithm. The details of the dataset are shown in Table 2.Figure 4
Clustering results on dataset 2d-3c. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Figure 5
Clustering results on dataset grid.orig. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Figure 6
Clustering results on dataset Jain. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Figure 7
Clustering results on dataset threecircles. (a) k-means. (b) DPC. (c) DBSCAN. (d) DDPC.
(a)(b)(c)(d)Table 1
Evaluation index of four algorithms on artificial datasets.
DatasetAlgorithmARINMIHomoF12d-3ck-means0.5898 ± 0.130.5733 ± 0.120.6056 ± 0.090.6619 ± 0.13DPC0.83090.81780.95620.9217DBSCAN0.81470.77530.74100.8328DDPC0.88200.85780.90070.9236grid.origk-means0.7601 ± 0.060.7164 ± 0.040.7121 ± 0.030.7367 ± 0.08DPC0.19880.30590.35260.3626DBSCAN0.98400.96630.96630.9915DDPC1.01.01.01.0Jaink-means0.4527 ± 0.090.3900 ± 0.070.4223 ± 0.080.4618 ± 0.11DPC1.01.01.01.0DBSCAN0.92620.82410.96900.9329DDPC1.01.01.01.0Threecirclesk-means0.0261 ± 0.020.1214 ± 0.010.1082 ± 0.030.1339 ± 0.02DPC0.09640.22730.35410.2846DBSCAN1.01.01.01.0DDPC1.01.01.01.0Flamek-means0.7323 ± 0.030.7154 ± 0.060.6987 ± 0.040.7432 ± 0.05DPC1.01.01.01.0DBSCAN0.98650.98650.99990.9873DDPC1.01.01.01.0Spiralk-means0.0164 ± 0.010.0321 ± 0.010.0289 ± 0.020.0236 ± 0.01DPC1.01.01.01.0DBSCAN1.01.01.01.0DDPC1.01.01.01.0Aggregationk-means0.7615 ± 0.030.7344 ± 0.020.7618 ± 0.060.7742 ± 0.05DPC1.01.01.01.0DBSCAN0.72210.73680.76390.8234DDPC0.99480.99150.99230.9974Lineblobsk-means0.5293 ± 0.080.6135 ± 0.110.6177 ± 0.070.6210 ± 0.12DPC0.64490.69330.68600.7128DBSCAN1.01.01.01.0DDPC1.01.01.01.0R15k-means0.8556 ± 0.030.8259 ± 0.030.8814 ± 0.010.8765 ± 0.02DPC0.97150.98330.97820.9867DBSCAN0.93640.92690.95160.9398DDPC0.98910.99130.99130.9950Sspiralk-means0.0237 ± 0.020.0231 ± 0.010.0216 ± 0.010.0253 ± 0.01DPC1.01.01.01.0DBSCAN1.01.01.01.0DDPC1.01.01.01.0Table 2
Artificial dataset.
DatasetInstanceDimensionCluster2d-3c71523Grid125022Jain37322Threecircles29923Flame21922Spiral31223Aggregation78827Lineblobs26623R15600215Sspiral94422Experimental results show that the DDPC algorithm proposed in this paper can achieve good clustering results on various difficult datasets in different density regions. At the same time, the DDPC algorithm can also achieve good clustering results for some nonconvex datasets. It can be seen from Figures4 and 5 that due to the limitation of parameters in other algorithms, a single parameter cannot solve the clustering problem of different density regions, resulting in a poor clustering effect. In Figure 6, the DBSCAN algorithm falls into local optimization and cannot cluster accurately. In Figure 7, because the density relationship of the dataset does not increase significantly, the DPC algorithm cannot cluster correctly due to the limitation of the density increasing condition. K-means algorithm cannot achieve a good clustering effect on nonconvex datasets. Therefore, it can be seen that the DDPC algorithm can achieve satisfactory clustering results whether it is a dataset with uneven density distribution or a nonconvex dataset, which cannot be done by other comparison algorithms.In terms of parameter sensitivity, DPC and DDPC are tested on the flame dataset. To accurately test the sensitivity of each parameter, based on the ARI evaluation index, we set one of the parameters as the ideal value and analyze the sensitivity of the parameter by observing the impact of the changes of other parameters on the clustering effect. The experimental results are shown in Figure8 and Tables 3–6. The observation results show that DDPC is superior to DPC in parameter sensitivity.Figure 8
Experimental results of parameter sensitivity on flame dataset. (a) DPC, (b) DPC, (c) DDPC, (d) DDPC.
(a)(b)(c)(d)Table 3
Experimental results of DPC on flame dataset whenK is optimal.
Dc0.10.20.30.40.50.60.70.80.91.0ARI0.291.00.960.010.010.010.010.00.010.01Table 4
Experimental results of DPC on flame dataset when dc is optimal.
K1234567ARI01.00.980.880.760.680.62Table 5
Experimental results of DDPC on flame dataset whenK is optimal.
R0.00.10.20.30.40.50.60.70.80.9ARI1.01.01.01.01.01.01.00.961.01.0Table 6
Experimental results of DDPC on flame dataset whenR is optimal.
K5101520253035ARI0.981.01.01.01.01.01.0


## 4.2. UCI Dataset

DDPC algorithm shows better clustering results on artificial datasets. To further verify its clustering performance, it also needs to be verified on the real datasets. Considering that the k-means algorithm has been proposed for a long time, this paper uses DBC (a novel clustering algorithm based on directional propagation of cluster labels) algorithm instead of K-means algorithm to compare on UCI dataset. After comparison, the comprehensive experimental results on a variety of different UCI datasets are better than DBC and other algorithms. UCI datasets are shown in Table7.Table 7
UCI datasets.
DatasetInstanceDimensionClusterVote435162WDBC569302Vowel87136Zoo101167Seeds21073Ecoli33678Banknote137242Dermatology358346Segment2310187Pendigits109921610In the UCI datasets, because it is difficult to visualize a high-dimensional dataset; the clustering evaluation indexes ARI, NMI, and homogeneity are compared. Table8 shows the evaluation indexes of each clustering algorithm. Although in the vowel dataset, the ARI of the DPC algorithm is slightly higher than that of the DDPC algorithm, and in the banknote dataset, the NMI of the DPC algorithm is slightly higher than that of the DDPC algorithm. However, in general, DDPC performs significantly better than other clustering algorithms on UCI datasets, and the clustering effect is the best. The second is the DBC algorithm and DPC algorithm. The clustering effect of the DBSCAN algorithm on the UCI dataset is the least ideal.Table 8
Evaluation index of four algorithms on UCI datasets.
DatasetAlgorithmARINMIHomoF1VoteDBSCAN0.44800.39770.50340.6106DPC0.00360.00310.02700.0107DBC0.57090.49420.50300.5236DDPC0.58500.52100.51160.8827WDBCDBSCAN0.46610.37900.38680.5131DPC0.48690.50280.51120.6628DBC0.58830.52580.66560.5669DDPC0.76680.68220.69970.9384VowelDBSCAN0.41700.53170.49020.4913DPC0.52310.59770.62850.6199DBC0.42210.55760.52420.4219DDPC0.51020.61560.65370.4948ZooDBSCAN0.14570.61610.62850.5266DPC0.30560.42220.32640.6953DBC0.88010.85450.76960.8752DDPC0.89180.86210.92750.8811SeedsDBSCAN0.00090.34260.42390.6137DPC0.76360.72190.71690.9127DBC0.78690.73980.73970.8623DDPC0.79160.77840.78190.9238EcoliDBSCAN0.14590.61610.62850.4523DPC0.45160.54020.72980.6404DBC0.71650.65710.55800.7653DDPC0.73980.70670.77050.8065BanknoteDBSCAN0.07520.29580.00560.1134DPC0.89350.93160.87610.9516DBC0.82980.74670.74270.8819DDPC0.95380.90990.90910.9883DermatologyDBSCAN0.41510.62050.64840.5761DPC0.42690.33040.41050.4429DBC0.78710.84860.78790.8626DDPC0.84590.90820.97030.6675SegmentDBSCAN0.24460.55250.42350.4695DPC0.24020.52620.40100.4968DBC0.36260.61090.62600.6371DDPC0.49650.65760.81440.7032PendigitsDBSCAN0.41510.62050.64840.5753DPC0.55420.72430.69380.7289DBC0.58180.66170.67040.7143DDPC0.63280.77750.96180.7695For DDPC, each data determine that the time complexity of the surroundingK neighbors is On2, the time complexity of calculating the local density and scanning distance is On, the time complexity of adaptive clustering is On∗k, and the overall time complexity of synthesizing the above information is On2. The time complexity of other algorithms compared in the experimental part is shown in Table 9.Table 9
Time complexity of each algorithm.
AlgorithmTime complexityk-meansOn∗k∗tDPCOn2DBSCANOn2DBCOn2DDPCOn2


## 4.3. Application

Wireless sensors are widely used in the Internet of things. The three functions of data acquisition, processing, and transmission are realized through a sensor network. Due to the large number and complex distribution of nodes in sensor networks, clustering can reduce the cost of information transmission between nodes. At the same time, some clustering algorithms can also eliminate the influence of noise data and improve experimental accuracy. Figure9 shows the difference in clustering accuracy between the DDPC algorithm and other clustering algorithms in the wireless sensor network dataset. The higher the clustering accuracy, the smaller the difference from the actual situation and the better the effect.Figure 9
Clustering results on dataset d1p07m.


## 5. Conclusion

A dynamic density peak clustering algorithm is proposed, which effectively solves the problem that the same parameter cannot adapt to different density regions in the process of density clustering. However, due to the limitations of adaptive processing, the main defects of the algorithm are two aspects: first, the adaptive algorithm is greatly affected by the dataset, resulting in the actual operation time being difficult to estimate, and the operation time of the dataset with a small amount of data may be longer than that of the dataset with a large amount of data. Second, for high-dimensional and large-scale data, the calculation efficiency of this algorithm is not high and may take a long time, but the calculation accuracy is greatly improved. In addition, we will try our best to further reduce the number of parameters in the future, but this needs to be realized by continuously optimizing the adaptive algorithm. In the experimental process, we found that the algorithm also has good performance on some datasets that are not suitable for density clustering, and the artificial datasets are completely consistent with the clustering labels. In some UCI datasets, although the performance of a single evaluation index is low, it is usually higher than other related algorithms. We also apply the algorithm to wireless sensor networks. The relative evaluation index of the application result is higher than that of the comparison algorithm, and the expected effect is achieved.In the future, on the basis of maintaining the existing accuracy, we will spend more energy to improve the computing efficiency and reduce the computing time of high-dimensional and large-scale data. Obviously, it takes a lot of time, but I am confident.



---

*Source: 7378801-2022-08-09.xml*