In my eyes everything is so simple, complicated I can not understand, most hate those complicated interpersonal relationships, alas, like a child to communicate well.
Learning K-means algorithm, will remind me of kingdoms this game, the interface is a map of China, the princes separated, respectively, according to. But the game starts, the player will be a person a city (I prefer this, it is challenging), and then continue to fight the parties, occupy the castle
Continue to expand the site, normally, the city of Conquest is closer to themselves, and then choose the central location of these cities as the main town. So after a while, there are several major areas of influence on the map, three pillars. This process is very similar to the K-means algorithm.
Next we think the game map as an example to explain the K-means algorithm, the map of each of the cities as a data sample (including the coordinates of the castle), if the game began to set three players (three cluster center K), the game aims to hope that the last three players are formed according to the pattern of the right figure. Start the game!
K-means (K-mean-value algorithm):
The first step is to introduce the overall flow of the algorithm
(1) Random initialization of the location of the cluster center
(2) Calculate the distance from each point to the center of the cluster, select the minimum value assigned to K (i)
(3) Moving the center of the cluster (in fact, it is the sample point of the average, that is, it moves is the position)
(4) Repetition (2), (3) until the loss function (i.e., the distance of all sample points to the center of the sample to which they belong)
Finally, the overall classification pattern will become stable.
The optimization goal, which is the loss function we used to mention before
In the continuous cycle, the center of the cluster is also constantly updated, until the sum of the upper-distance convergence of the exact value of the time to obtain the optimal solution.
(1) Random initialization
For the fairness of the game, the three gamers are randomly assigned to the three cities on the map (it is important to note that the number of cluster centers must be less than the number of data samples). Random initialization will meet the following scenarios
1 Good things.
This is best because the three cluster centers are well spread over three main sample classes, and the following algorithms can be used to form the classification we want.
2
This situation is not very good, the red dot and green Point are allocated in the beginning, so the opening will have a confrontation, for bad initialization may produce the following clustering results
This situation is very bad, does not meet the requirements.
We do not have a good solution to this situation, you can try to initialize multiple times, get the best results, such as set 1000 random initialization, select the loss function value of the least one.
In another case, how can you correctly select the number of cluster centers for datasets that are not inherently distributed by some datasets, such as:
Using the (elbow method) "Elbow algorithm":
get the function image of loss function and cluster center K, there are roughly two kinds of image types
The inflection point of the left figure is obvious, and the right corner is not very obvious, for the left we can choose the number of K as the center of the cluster, and if it is right, then we need to choose according to the situation, for example, if the data set is the size of the clothing data, if you want to determine the size of these clothes type, So depending on what type of size you want to divide into (for example: L,m,s) (and, M,l,xl,xxl,s)
K-means algorithm in my eyes