Improved K-means clustering algorithm based on expectation factor and weighting constraint
By combining the weighted constraint values of density and distance in the K-means algorithm, the local optimal problem of traditional K-means algorithm in high dimensions and large data volumes is solved, and cluster stability and effect are improved .
Patent Information
- Application Number
- CN202411403807.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-01-03
AI Technical Summary
The clustering effect and stability of the traditional K-means algorithm are affected by the selection of the initial clustering center, especially in the case of high-dimensionality and large data volume, it is easy to fall into local optimization. The existing improvement solutions mainly range from the density or distance. Starting, it failed to effectively integrate the two.
Using an improved K-means algorithm based on the expected factor and weighted constraints, the grid density and distance are calculated, the initial clustering center is selected, and the weighted constraint values of density and distance are combined, and the grid division standards are clarified to reduce the randomness of the initial center point. .
It improves the clustering effect and the stability of the results, reduces the number of iterations, adapts to the characteristics of high-dimensionality and large data volume, and avoids the local optimal problem of clustering results.
Smart Images

Figure CN119249187A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of data analysis, and in particular relates to an improved K-means clustering algorithm based on expected factors and weighted constraints. Background Art
[0002] Cluster analysis is an important technology in data mining. K-means algorithm is a partition-based clustering algorithm with low algorithm complexity and excellent clustering effect. It is widely used in data mining and machine learning. However, the clustering effect and stability of the traditional K-means algorithm are affected by the K value and the selection of the initial cluster center. An unreasonable selection scheme may even cause the clustering result to fall into a local optimum. In the 5G era, the dimensions of data samples are high and the data volume is large. The disadvantages of the traditional K-means algorithm are becoming more and more obvious, and there is an urgent need to improve the K-means algorithm.
[0003] In the K-means algorithm, the selection of the initial cluster center has a great influence on the clustering results. The final clustering results are often different when different initial cluster centers are selected. Therefore, the stability of the K-means clustering algorithm is poor, and the randomness of the selection of cluster centers will cause the clustering results to fall into the local optimum. At present, the improvement research on the selection of initial cluster centers mainly starts from the two aspects of density and distance. The density-based K-means algorithm improvement scheme mainly selects according to the density distribution of data points in the data set to avoid the situation where the clustering falls into the local optimum due to the excessive density of the randomly selected initial cluster centers. For example, the initial cluster center is optimized by weighting the local variance. The variance represents the degree of discreteness of the data. The smaller the variance, the smaller the degree of discreteness, the greater the density, and the more suitable it is for the initial cluster center. The distance-based K-means algorithm improvement scheme mainly proposes the concept of dissimilarity based on Euclidean distance, and judges the differences between data sample points by constructing a dissimilarity matrix, and thereby judges whether the data sample points can be used as initial cluster centers. For example, define the dissimilarity of the kth attribute between two data points, standardize the data, and then construct a dissimilarity matrix.
[0004] Chinese patent CN117634745A (publication date March 1, 2024) discloses a time-of-use electricity price period division method based on an improved K-means clustering algorithm, which belongs to the field of cluster analysis technology, including: preparing day-ahead load data, fuzzy membership function, silhouette coefficient, data density, and K-means clustering algorithm. First, the cluster center is initialized using the fuzzy membership function; then the K-means clustering algorithm is run multiple times and the silhouette coefficient is used to evaluate the clustering effect to determine the optimal number of clusters; then the initial cluster center is optimized according to the data density to meet the optimal number of clusters; finally, the K-means clustering algorithm is run to divide the load period, and the division results are compared to output the optimal period division.
[0005] Chinese patent CN117786441A (publication date March 29, 2024) discloses a multi-scenario photovoltaic user electricity consumption behavior analysis method based on an improved K-means clustering algorithm, including the following steps: obtaining historical data and preprocessing the historical data; using a particle swarm algorithm to preliminarily optimize the K-means clustering algorithm based on the preprocessed data; using the preliminarily optimized K-means clustering algorithm to perform clustering analysis to obtain preliminary cluster clustering results; using the KPCA method to extract the features of the preliminary clusters; using the DTW method to perform similarity analysis on the extracted features and establish a cumulative distance minimum matrix; based on the cumulative distance minimum matrix, performing secondary optimization on the preliminarily optimized K-means clustering algorithm; obtaining the final cluster clustering results based on the secondary optimized K-means clustering algorithm, and analyzing the photovoltaic user electricity consumption behavior based on the final cluster clustering results.
[0006] The existing K-means algorithm improvement mainly starts from one aspect of density or distance, or is divided into two steps, without directly integrating the two factors of density and distance, and there is still room for further improvement. The present invention comprehensively considers the two factors of density and distance, integrates density and distance into one formula, adopts the idea of weighted constraints to improve the randomness of the initial center point, studies a more efficient and accurate improved K-mean algorithm, and determines the grid division standard according to the expected factor, which is easy to expand to high dimensions and better adapt to the characteristics of high data dimensions and large data volumes in the future. Summary of the invention
[0007] The present invention mainly solves the problems of poor clustering effect and unstable clustering result caused by the randomness of the initial clustering center of the K-means algorithm, clarifies the grid division standard, comprehensively considers the two factors of density and distance, and provides an improved K-means clustering algorithm based on expectation factor and weighted constraint.
[0008] An improved K-means clustering algorithm based on expectation factor and weighted constraint includes the following steps:
[0009] Step S1: Input the expected factor t, the number of samples n, the sample dimension m, the number of clusters K, and the sample set N = {x1, x2, ..., x n}, where x i ={x i1 ,x i2 ,…,x im};
[0010] Step S2: Calculate the number of grid components a in each dimension according to the expected factor t, the number of samples n, the sample dimension m and the number of clusters K. The calculation formula is:
[0011]
[0012] In the formula To round down the symbol, divide the sample set N evenly into A small grid;
[0013] Step S3: Calculate the number of samples in each small grid, recorded as grid density d i , remove the grids whose grid density is less than the expected factor, and arrange the other grids in descending order of grid density in the new sample set O;
[0014] Step S4: Select the center point of the grid with the highest grid density as the first initial cluster center point, that is, the center point of o1 in the new sample set O. First, calculate the distance between it and other grid center points in the new sample set O, denoted as l i , and then calculate the weighted constraint value w i , the calculation formula is:
[0015]
[0016] In the formula, d and l are the sum of the grid density and the sum of the distances of all samples in the new sample set O, respectively. The sample o with the largest weighted constraint value is selected. i The center point of is the next initial cluster center point;
[0017] Step S5: Based on the newly selected initial cluster center point, repeat step S4 until K initial cluster center points {y1, y2, …, y k};
[0018] Step S6: For the sample set N = {x1, x2, ..., x n}, and perform traditional K-means clustering with the selected K initial cluster centers.
[0019] The expected factor t in step S1 is an integer and is less than n / K. m .
[0020] In the step S2, the maximum value and the minimum value in the sample set N are firstly extracted to form an m-dimensional distribution range, the projection in each dimensional direction is a rectangle, and then the grid is evenly divided according to the calculation results.
[0021] The distance metric selected in step S4, step S5 and step S6 is the Euclidean distance, and the calculation formula is:
[0022]
[0023] The objective function is:
[0024] The step S6 specifically includes:
[0025] Step S6.1: Calculate x i With y i The Euclidean distance is , and the sample is assigned to the cluster center with the closest distance;
[0026] Step S6.2: recalculate the average value of each cluster and update it as the new cluster center;
[0027] Step S6.3: Repeat steps S6.1 and S6.2 until the objective function converges or the maximum number of iterations is reached, and output the clustering result Z = {Z1, Z2, ..., Z k}.
[0028] Compared with the prior art, the advantages and effects of this application are as follows:
[0029] 1. The present invention proposes an improved K-means clustering algorithm based on expected factor and weighted constraint, which clarifies the grid division standard through the expected factor, comprehensively considers the two factors of density and distance, avoids the clustering from falling into the local optimum, greatly reduces the number of iterations, and improves the clustering effect and the stability of clustering results.
[0030] 2. The present invention proposes an improved K-means clustering algorithm based on expectation factor and weighted constraint, which comprehensively considers the two factors of density and distance, integrates density and distance into one formula, adopts the idea of weighted constraint to improve the randomness of the initial center point, and studies a more efficient and accurate improved K-mean algorithm that is easy to expand to high dimensions and better adapt to the characteristics of high data dimension and large data volume in the future.
[0031] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application so that it can be implemented in accordance with the contents of the specification, and to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the following is a detailed description of the preferred embodiments of the present application in conjunction with the accompanying drawings as follows.
[0032] Based on the detailed description of the specific embodiments of the present application in combination with the accompanying drawings below, those skilled in the art will become more aware of the above and other objects, advantages and features of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings without creative work. In all drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, each element or part is not necessarily drawn according to the actual scale.
[0034] in:
[0035] Figure 1 It is a simplified flow chart of an improved K-means clustering algorithm based on expected factor and weighted constraint;
[0036] Figure 2 This is a flowchart of an improved K-means clustering algorithm based on expected factor and weighted constraints. Specific embodiments
[0037] To make the purpose, technical scheme and advantages of the embodiment of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiment of the present application. Obviously, the described embodiment is a part of the embodiment of the present application, rather than all of the embodiments. In the following description, specific details such as specific configuration and components are provided only to help fully understand the embodiments of the present application. Therefore, it should be clear to those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. In addition, for clarity and brevity, the description of known functions and structures is omitted in the embodiment.
[0038] It should be understood that the references to "one embodiment" or "this embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present application. Therefore, the references to "one embodiment" or "this embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0039] In addition, the present application may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplicity and clarity, and does not in itself indicate the relationship between the various embodiments and / or settings discussed.
[0040] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" in this article describes another type of association object relationship, indicating that there can be two relationships. For example, A / and B can mean: A exists alone, and A and B exist alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0041] The term "at least one" in this article is merely a description of the association relationship of associated objects, indicating that there may be three relationships. For example, at least one of A and B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0042] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusions.
[0043] Example 1
[0044] This embodiment designs an improved K-means clustering algorithm based on expected factors and weighted constraints. Figure 1 As shown:
[0045] Step S1: Calculate the grid partition standard according to the expected factor;
[0046] Step S2: Calculate the grid density and remove low-density grids;
[0047] Step S3: Select the center point of the grid with the largest grid density as the first initial cluster center;
[0048] Step S4: Calculate the weighted constraint value of the distance between grid samples and the grid density;
[0049] Step S5: Select the one with the largest weighted constraint value as the next initial cluster center;
[0050] Step S6: Repeat the process to select K initial cluster centers;
[0051] Step S7: Perform traditional K-means clustering on the sample data.
[0052] By inputting the expected factor t, the number of samples n, the sample dimension m, the number of clusters K, and the sample set N = {x1, x2, ..., x n}, where x i ={xi1 ,x i2 ,…,x im}, the sample set consists of n m-dimensional vectors, where the expected factor parameter t takes an integer value with a limited range. A reasonable t value can better exert the superiority of the algorithm. First, obtain the distribution range of the entire sample set, calculate the partition standard according to the formula, evenly partition into multiple small grids, and calculate the number of samples in each grid, that is, the grid density d i , according to the expected factor, the grids with low density are eliminated and arranged in descending order into the new sample set O, the center point of the grid with the largest density is selected as the first initial cluster center, and the distance from the center points of other grids in the sample set O to the first initial cluster center is calculated. The weighted constraint value of the grid density and distance is calculated according to the formula, and the weighted constraint value with the largest weighted constraint value is selected as the next initial cluster center. Based on this initial cluster center, the weighted constraint value in the sample set O is repeatedly calculated until enough K initial cluster centers are selected, which are recorded as {y1,y2,…,y k}, perform traditional K-means clustering on the sample set N, and output the clustering result Z = {Z1, Z2, …, Z k}.
[0053] The present invention proposes an improved K-means clustering algorithm based on expectation factor and weighted constraint, which comprehensively considers the two factors of density and distance, integrates density and distance into one formula, adopts the idea of weighted constraint to improve the randomness of the initial center point, and studies a more efficient and accurate improved K-mean algorithm that is easy to expand to high dimensions and better adapt to the characteristics of high data dimension and large data volume in the future.
[0054] Example 2
[0055] This embodiment designs an improved K-means clustering algorithm based on expected factors and weighted constraints. Figure 2 As shown, it is further designed based on the steps described in Example 1.
[0056] Step 1: Input the expected factor t, the number of samples n, the sample dimension m, the number of clusters K, and the sample set N = {x1, x2, ..., x n}, where x i ={x i1 ,x i2 ,…,x im}; The expected factor t in step S1 is an integer and is less than n / K m .
[0057] Step S2: Calculate the number of grid components a in each dimension according to the expected factor t, the number of samples n, the sample dimension m and the number of clusters K. The calculation formula is:
[0058]
[0059] In the formula To round down the symbol, divide the sample set N evenly into A small grid;
[0060] In the step S2, the maximum value and the minimum value in the sample set N are firstly extracted to form an m-dimensional distribution range, the projection in each dimensional direction is a rectangle, and then the grid is evenly divided according to the calculation results.
[0061] Step S3: Calculate the number of samples in each small grid, recorded as grid density d i , remove the grids whose grid density is less than the expected factor, and arrange the other grids in descending order of grid density in the new sample set O;
[0062] Step S4: Select the center point of the grid with the highest grid density as the first initial cluster center point, that is, the center point of o1 in the new sample set O. First, calculate the distance between it and other grid center points in the new sample set O, denoted as l i , and then calculate the weighted constraint value w i , the calculation formula is:
[0063]
[0064] In the formula, d and l are the sum of the grid density and the sum of the distances of all samples in the new sample set O, respectively. The sample o with the largest weighted constraint value is selected. i The center point of is the next initial cluster center point;
[0065] Step S5: Based on the newly selected initial cluster center point, repeat step S4 until K initial cluster center points {y1, y2, ..., y k};
[0066] The distance metric selected in step S4, step S5 and step S6 is the Euclidean distance, and the calculation formula is:
[0067]
[0068] The objective function is:
[0069] The step S6: for the sample set N = {x1, x2, ..., x n}, and perform traditional K-means clustering with the selected K initial cluster centers.
[0070] The step S6 specifically includes:
[0071] Step S6.1: Calculate the Euclidean distance between xi and yi, and assign the sample to the cluster center with the closest distance;
[0072] Step S6.2: recalculate the average value of each cluster and update it as the new cluster center;
[0073] Step S6.3: Repeat steps S6.1 and S6.2 until the objective function converges or the maximum number of iterations is reached, and output the clustering result Z = {Z1, Z2, ..., Z k}.
[0074] The present invention proposes an improved K-means clustering algorithm based on expected factor and weighted constraint, which clarifies the grid division standard through the expected factor, comprehensively considers the two factors of density and distance, avoids the clustering falling into the local optimum, greatly reduces the number of iterations, and improves the clustering effect and the stability of clustering results.
[0075] The above description is only the preferred embodiment of the present invention, which does not limit the protection scope of the present invention. For those skilled in the art, the present invention can be modified and varied in various ways. Within the spirit and principle of the present invention, any change, modification, replacement, integration and parameter change of these embodiments by conventional substitution or capable of achieving the same function without departing from the principle and spirit of the present invention shall fall within the protection scope of the present invention.
Claims
1. An improved K-means clustering algorithm based on expectation factor and weighted constraint, characterized in that: The following steps are involved: Step S1: Input the expected factor t, the number of samples n, the sample dimension m, the number of clusters K, and the sample set N = {x1, x2, ..., x n }, where x i ={x i1 ,x i2 ,…,x im }; Step S2: Calculate the number of grid components a in each dimension according to the expected factor t, the number of samples n, the sample dimension m and the number of clusters K. The calculation formula is: In the formula To round down the symbol, divide the sample set N evenly into A small grid; Step S3: Calculate the number of samples in each small grid, recorded as grid density d i , remove the grids whose grid density is less than the expected factor, and arrange the other grids in descending order of grid density in the new sample set O; Step S4: Select the center point of the grid with the highest grid density as the first initial cluster center point, that is, the center point of o1 in the new sample set O. First, calculate the distance between it and other grid center points in the new sample set O, denoted as l i , and then calculate the weighted constraint value w i , the calculation formula is: In the formula, d and l are the sum of the grid density and the sum of the distances of all samples in the new sample set O, respectively. The sample o with the largest weighted constraint value is selected. i The center point of is the next initial cluster center point; Step S5: Based on the newly selected initial cluster center point, repeat step S4 until K initial cluster center points {y1, y2, …, y k }; Step S6: For the sample set N = {x1, x2, ..., x n }, and perform traditional K-means clustering with the selected K initial cluster centers.
2. The improved K-means clustering algorithm based on expectation factor and weighted constraint according to claim 1, characterized in that: The expected factor t in step S1 is an integer and is less than n / K. m .
3. The improved K-means clustering algorithm based on expectation factor and weighted constraint according to claim 1, characterized in that: In the step S2, the maximum value and the minimum value in the sample set N are firstly extracted to form an m-dimensional distribution range, the projection in each dimensional direction is a rectangle, and then the grid is evenly divided according to the calculation results.
4. The improved K-means clustering algorithm based on expectation factor and weighted constraint according to claim 1, characterized in that: The distance metric selected in step S4, step S5 and step S6 is the Euclidean distance, and the calculation formula is: The objective function is:
5. The improved K-means clustering algorithm based on expectation factor and weighted constraint according to claim 4, characterized in that: The step S6 specifically includes: Step S6.1: Calculate x i With y i The Euclidean distance is , and the sample is assigned to the cluster center with the closest distance; Step S6.2: recalculate the average value of each cluster and update it as the new cluster center; Step S6.3: Repeat steps S6.1 and S6.2 until the objective function converges or the maximum number of iterations is reached, and output the clustering result Z = {Z1, Z2, ..., Z k }.
Citation Information
Patent Citations
Time-of-use electricity price period division method based on improved K-means clustering algorithm
CN117634745A
Multi-scene photovoltaic user power consumption behavior analysis method based on improved K-means clustering algorithm
CN117786441A