# Why kmeans cluster breakup is like this [closed]

I have a galaxy spectrum data set (total 22000). Similar to an electronic wave data, two dimensional (Flux vs Wavelength). A typical set of wavelength plot looks like below

Now I am doing kmeans on this data set to cluster them based on their spectrum shape/pattern only (using sci-kit learn). Some results of the k means clustering is baffling me, I have made a flow chart of how the candidates clustered as I would go on increasing the number of clusters from k=2 to k=5. The flow chart graph of the division of candidates is below (this is on a smaller subset),

Now my most basic question is why is the division of points in clusters happening like it is seen in the plot, as we traverse down the graph. More specifically, why for example in k=4 case in Cluster=1 it makes a group with such a mix bag ? couldnt kmeans instead select it's constituent 1078 or 580 candidates into a single (more cleaner) cluster ? Also is it a coincidence that there is always an identified 13 members group (in golden arrow) (or a 47).

• It is an interesting way to visualize k-means. Since you have a 2D data, have you tried visualizing it something like the graph you see here?
– sai
Oct 1, 2020 at 10:58
• @sai , individual waves are of array 5000 length. So it is not a 2D data. Kmeans would cluster based on the wavelength distribution on this arrays. so it is a high dimenionsal data. Am I correct ? Oct 1, 2020 at 12:08
• I do not think the length matters. Just the space in which your waves vary i.e., the min and max values of the flux and wavelength matter.
– sai
Oct 1, 2020 at 12:13
• How do you generate that chart? What do the individual arrows/colors mean? Oct 1, 2020 at 13:56
• You can't visualize directly in 2D as you are in 5000D however you can use a tool such as t-SNE to visualize your data points in 2D (try different parameters of perplexity) and check in the 2D space from t-SNE how are distributed clusters from KNN (@ sai I think KNN is not performed on indivual (time, value) points but rather on the whole signals, signals with similar shapes will be closer) Oct 1, 2020 at 15:10