K-means initial clustering center determination method comprehensively considering distance and density
By selecting the initial clustering center of the k-means algorithm by comprehensively considering distance and density, the problem of easy selection of noise data and isolated points in traditional methods is solved, and the stability and efficiency of the algorithm are improved.
Patent Information
- Application Number
- CN202411631833.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-03-07
AI Technical Summary
The traditional k-means algorithm easily selects noise data and isolated points when selecting the initial clustering center, resulting in an increase in the number of iterations, a decrease in time performance and a tendency to fall into local optimality.
The initial cluster center is determined by comprehensively considering distance and density. By calculating the density coefficient of the sample points and filtering out the points with high density and far distances as the initial cluster center.
It improves the rationality of the clustering center, significantly improves the stability and computing efficiency of the algorithm, and avoids the risk of falling into local optimality.
Smart Images

Figure CN119577495A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of power consumption data analysis of power users, and in particular relates to a k-means initial clustering center determination method that comprehensively considers distance and density. Background Art
[0002] In recent years, with the development of smart grids, power data has shown a trend of massive big data. As a data-intensive industry, the power industry has also begun to focus on mining the value of data, thereby improving its overall level and industry competitiveness. By systematically and strategically managing big data obtained from inside and outside the smart grid, management decisions for grid operations can be effectively supported. Among them, user power behavior analysis based on feature optimization is a necessary prerequisite for supporting optimized scheduling of power demand response.
[0003] K-means is a simple and efficient clustering algorithm based on the idea of partitioning. It is also one of the ten classic algorithms in data mining and is suitable for clustering problems of large-scale data. The traditional k-means algorithm randomly selects the initial cluster center, and this randomness will have a great impact on the result. It is easy to select noise data and isolated points, which makes the algorithm iteration number more, the time performance deteriorates, and it is easy to fall into the local optimum. In order to solve the randomness problem, k sample points with a relatively long distance are generally selected as cluster centers, but if only the distance is considered, outliers or noise points may be obtained, which has a greater impact on the final result. For this reason, the present invention comprehensively considers the two reference quantities of density and distance to select the initial cluster center, so that the cluster center is more reasonable in selection. Summary of the invention
[0004] Purpose of the invention: The technical problem to be solved by the present invention is to provide a k-means initial clustering center determination method that comprehensively considers distance and density in view of the deficiencies in the prior art.
[0005] Technical solution: In order to achieve the above-mentioned invention object, the present invention proposes a k-means initial clustering center determination method that comprehensively considers distance and density, and the method comprises the following steps:
[0006] 1) Set the neighborhood value ε and the minimum density coefficient threshold D according to the residential electricity consumption data sample set min ;
[0007] 2) Calculate the Euclidean distance Euclid between any two sample points;
[0008] 3) According to the neighborhood value ε and the Euclidean distance Euclid, the density coefficient den(x i ), delete the density coefficient less than the minimum density coefficient threshold D min The density sample points of the density point set D are obtained;
[0009] 4) Determine the initial cluster center, take the point c1 with the highest density coefficient in D as the first initial cluster center, take the sample point in D that is farthest from c1 as the second initial cluster center c2, take the point in D that has the largest sum of the minimum distances from c1 and c2 as the third initial cluster center c3, and so on to obtain k initial cluster centers;
[0010] 5) Traverse the sample set, find the cluster center closest to each sample point, and divide the sample set into k clusters;
[0011] 6) Determine the final cluster center, calculate the center point of all data in each cluster respectively, use the geometric center of each cluster as the new cluster center point, and obtain new k cluster centers;
[0012] 7) Convergence judgment: when the cluster centers obtained in step 6 are consistent with those obtained in step 4, the algorithm converges; otherwise, return to step 4.
[0013] Furthermore, in step 1), the neighborhood value and the minimum density coefficient threshold are related to the distribution and quantity of samples, and the calculation method of the neighborhood value of the sample set is:
[0014]
[0015] Among them, ε represents the neighborhood value, S represents the user sample data set, a and b represent the subscripts of any two sample points; x a ,x b Represents any two samples in the sample data set; Euclid(x a ,x b ) represents the Euclidean distance between two sample points; Indicates the maximum Euclidean distance between any two sample points in the data set S; Represents the minimum Euclidean distance between two sample points in the data set S;
[0016] Minimum density threshold D min The calculation method is:
[0017]
[0018] Among them, i represents the subscript of any sample point, x i represents the i-th sample point; n represents the sample point x i The dimension of den(x i ) represents the sample point x i The density coefficient of the minimum density threshold is rounded based on the calculated result.
[0019] Furthermore, in step 2), the Euclidean distance is calculated as follows:
[0020]
[0021] Among them, x a and x b represents any two sample points, each sample point contains n-dimensional data; j represents the jth dimension in the sample point, x aj and x bj Represents the sample point x a and x b The j-th dimension data value in , each household is regarded as a sample, each sample contains n-dimensional data, the data includes the power consumption of washing machine, air conditioner, and TV, n = 3.
[0022] Furthermore, in step 3), the den(x i ) represents the distance from the sample point x i The number of sample points with a Euclidean distance of ε is obtained by enumeration. The larger the density coefficient of the sample point, the higher the sample density of the area where it is located, and vice versa.
[0023] In addition, the present invention provides a computer device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of any one of the methods for determining the initial clustering center of k-means that comprehensively considers distance and density are implemented.
[0024] In addition, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of a method for determining a k-means initial clustering center that comprehensively considers distance and density as described in any one of the claims are implemented.
[0025] Beneficial effects: Compared with the prior art, the technical solution of the present invention has the following beneficial technical effects:
[0026] The present invention provides a method for determining the initial cluster center of k-means that comprehensively considers distance and density. Compared with the prior art, the present invention comprehensively considers two reference quantities, density and distance, to select the initial cluster center, thereby avoiding the shortcomings of the prior art methods, which are easy to select noise data and isolated points, a large number of iterations, poor time performance, and easy to fall into local optimum. The present invention makes the selection of cluster centers more reasonable, and can significantly improve the stability and computational efficiency of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 The present invention provides a flow chart of a method for determining a k-means initial clustering center that comprehensively considers distance and density.
[0028] Figure 2 A comparison diagram of the final cluster center and the initial cluster center obtained by using the traditional clustering method and the method proposed by the present invention. DETAILED DESCRIPTION
[0029] The present invention is further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent modifications of the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
[0030] like Figure 1 As shown, in order to achieve the above-mentioned invention object, the present invention proposes a k-means initial clustering center determination method that comprehensively considers distance and density, and the method comprises the following steps:
[0031] 1) Set the neighborhood value ε and the minimum density coefficient threshold D according to the residential electricity consumption data sample set min ;
[0032] 2) Calculate the Euclidean distance Euclid between any two sample points;
[0033] 3) According to the neighborhood value ε and the Euclidean distance Euclid, the density coefficient den(x i ), delete the density coefficient less than the minimum density coefficient threshold D min The density sample points of the density point set D are obtained;
[0034] 4) Determine the initial cluster center, take the point c1 with the highest density coefficient in D as the first initial cluster center, take the sample point in D that is farthest from c1 as the second initial cluster center c2, take the point in D that has the largest sum of the minimum distances from c1 and c2 as the third initial cluster center c3, and so on to obtain k initial cluster centers;
[0035] 5) Traverse the sample set, find the cluster center closest to each sample point, and divide the sample set into k clusters;
[0036] 6) Determine the final cluster center, calculate the center point of all data in each cluster respectively, use the geometric center of each cluster as the new cluster center point, and obtain new k cluster centers;
[0037] 7) Convergence judgment: when the cluster centers obtained in step 6 are consistent with those obtained in step 4, the algorithm converges; otherwise, return to step 4.
[0038] Furthermore, in step 1), the neighborhood value and the minimum density coefficient threshold are related to the distribution and quantity of samples, and the calculation method of the neighborhood value of the sample set is:
[0039]
[0040] Among them, ε represents the neighborhood value, S represents the user sample data set, a and b represent the subscripts of any two sample points; x a ,x b Represents any two samples in the sample data set; Euclid(x a ,x b ) represents the Euclidean distance between two sample points; Indicates the maximum Euclidean distance between any two sample points in the data set S; Represents the minimum Euclidean distance between two sample points in the data set S;
[0041] Minimum density threshold D min The calculation method is:
[0042]
[0043] Among them, i represents the subscript of any sample point, x i represents the i-th sample point; n represents the sample point x i The dimension of den(x i ) represents the sample point x i The density coefficient of the minimum density threshold is rounded based on the calculated result.
[0044] Furthermore, in step 2), the Euclidean distance is calculated as follows:
[0045]
[0046] Among them, x a and x b represents any two sample points, each sample point contains n-dimensional data; j represents the jth dimension in the sample point, x aj and x bj Represents the sample point x a and x b The j-th dimension data value in , each household is regarded as a sample, each sample contains n-dimensional data, the data includes the power consumption of washing machine, air conditioner, and TV, n = 3.
[0047] Furthermore, in step 3), the den(x i ) represents the distance from the sample point x i The number of sample points with a Euclidean distance of ε is obtained by enumeration. The larger the density coefficient of the sample point, the higher the sample density of the area where it is located, and vice versa.
[0048] In addition, the present invention provides a computer device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of any one of the methods for determining the initial clustering center of k-means that comprehensively considers distance and density are implemented.
[0049] In addition, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of a method for determining a k-means initial clustering center that comprehensively considers distance and density as described in any one of the claims are implemented.
[0050] In order to verify the effectiveness of the method proposed in the present invention, a comparative analysis of multiple algorithms was performed using the public dataset wine released by UCI. The UCI database is a database specifically used to test machine learning and data mining algorithms. The data in the database have certain classifications, so the quality of clustering can be intuitively measured by using accuracy as an evaluation indicator. The dataset wine contains a total of 178 samples, with 13 features and 3 categories. 5% of early noise data was added to the dataset, and the final cluster centers were obtained using the traditional clustering method and the method proposed in the present invention. The comparison between the final cluster centers and the initial cluster centers is shown in Figure 2. Figure 2 It can be found that randomly selected cluster centers may select noise points, while the proposed method takes into account both distance and density measurements. By comparing the density coefficient, outlier and scattered noise points can be screened out, so the application effect is better.
[0051] The above only expresses the implementation methods of the invention, which are described in a more specific and detailed manner, but cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the invention, which all belong to the protection scope of the invention. Therefore, the protection scope of the invention patent shall be based on the attached claims.
Claims
1. A method for determining the initial clustering center of k-means by comprehensively considering distance and density, characterized in that: The method comprises the following steps: 1) Set the neighborhood value ε and the minimum density coefficient threshold D according to the residential electricity consumption data sample set min ; 2) Calculate the Euclidean distance Euclid between any two sample points; 3) According to the neighborhood value ε and the Euclidean distance Euclid, the density coefficient den(x i ), delete the density coefficient less than the minimum density coefficient threshold D min The density sample points of the density point set D are obtained; 4) Determine the initial cluster center, take the point c1 with the highest density coefficient in D as the first initial cluster center, take the sample point in D that is farthest from c1 as the second initial cluster center c2, take the point in D that has the largest sum of the minimum distances from c1 and c2 as the third initial cluster center c3, and so on to obtain k initial cluster centers; 5) Traverse the sample set, find the cluster center closest to each sample point, and divide the sample set into k clusters; 6) Determine the final cluster center, calculate the center point of all data in each cluster respectively, use the geometric center of each cluster as the new cluster center point, and obtain new k cluster centers; 7) Convergence judgment: when the cluster centers obtained in step 6 are consistent with those obtained in step 4, the algorithm converges; otherwise, return to step 4.
2. The k-means initial clustering center determination method taking distance and density into consideration according to claim 1, characterized in that: In step 1), the neighborhood value and the minimum density coefficient threshold are related to the distribution and quantity of samples. The calculation method of the neighborhood value of the sample set is: Where ε represents the neighborhood value, S represents the user sample data set, a and b represent the subscripts of any two sample points; x a , x b Represents any two samples in the sample data set; Euclid(x a , x b ) represents the Euclidean distance between two sample points; Indicates the maximum Euclidean distance between any two sample points in the data set S; Represents the minimum Euclidean distance between two sample points in the data set S; Minimum density threshold D min The calculation method is: Among them, i represents the subscript of any sample point, x i represents the i-th sample point; n represents the sample point x i The dimension of den(x i ) represents the sample point x i The density coefficient of the minimum density threshold is rounded based on the calculated result.
3. The k-means initial clustering center determination method taking into account distance and density according to claim 2, characterized in that: In the step 2), the Euclidean distance is calculated as follows: Among them, x a and x b represents any two sample points, each sample point contains n-dimensional data; j represents the jth dimension in the sample point, x aj and x bj Represents the sample point x a and x b The j-th dimension data value in , each household is regarded as a sample, each sample contains n-dimensional data, the data includes the power consumption of washing machine, air conditioner, and TV, n = 3.
4. The method for determining the initial clustering center of k-means by comprehensively considering distance and density according to claim 3, characterized in that: In the step 3), the den(x i ) represents the distance from the sample point x i The number of sample points whose Euclidean distance is ε.
5. A computer device, characterized in that: The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of a method for determining an initial clustering center of k-means that comprehensively considers distance and density as described in claims 1-4 are implemented.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the steps of the method for determining the initial clustering center of k-means that comprehensively considers distance and density as described in claims 1-4 are implemented.