What are the best (recommended) pre-processing steps before performing k-means?


If your variables are of incomparable units (e.g. height in cm and weight in kg) then you should standardize variables, of course. Even if variables are of the same units but show quite different variances it is still a good idea to standardize before K-means. You see, K-means clustering is "isotropic" in all directions of space and therefore tends to produce more or less round (rather than elongated) clusters. In this situation leaving variances unequal is equivalent to putting more weight on variables with smaller variance, so clusters will tend to be separated along variables with greater variance.

enter image description here

A different thing also worth to remind is that K-means clustering results are potentially sensitive to the order of objects in the data set$^1$. A justified practice would be to run the analysis several times, randomizing objects order; then average the cluster centres of those runs and input the centres as initial ones for one final run of the analysis.

Here is some general reasoning about the issue of standardizing features in cluster or other multivariate analysis.

$^1$ Specifically, (1) some methods of centres initialization are sensitive to case order; (2) even when the initialization method isn't sensitive, results might depend sometimes on the order the initial centres are introduced to the program by (in particular, when there are tied, equal distances within data); (3) so-called running means version of k-means algorithm is naturaly sensitive to case order (in this version - which is not often used apart from maybe online clustering - recalculation of centroids take place after each individual case is re-asssigned to another cluster).

  • 2
    $\begingroup$ The randomizing, re-running, averaging and final run is a very good advice. Thanks $\endgroup$ – pedrosaurio Jan 30 '12 at 16:08
  • 1
    $\begingroup$ How would k-means be sensitive to ordering? $\endgroup$ – SmallChess Feb 23 '17 at 5:39
  • 1
    $\begingroup$ @StudentT, I've added a footnote for that. Thank you. $\endgroup$ – ttnphns Feb 23 '17 at 7:19
  • 1
    $\begingroup$ @ttnphns how do determine quantitatively that variables have "quite different variances"? $\endgroup$ – Herman Toothrot Oct 18 '18 at 12:09
  • 1
    $\begingroup$ @camillejr, please start by checking this Q: stats.stackexchange.com/q/418427/3277. $\endgroup$ – ttnphns Nov 6 '19 at 18:06

Depends on your data I guess. If you would like trends in your data to cluster together regardless of the magnitude, you should center. eg. say you have some gene expression profile, and want to see trends in gene expression, then without mean centering, your low expression genes will cluster together and away from high expression genes, regardless of trends. Centering makes genes (both high and low expressed) with like expression patterns cluster together.

  • $\begingroup$ I am actually comparing different features that have their own scale. For instance I am comparing GC content which has a range from about 0.3 to 0.5 which may seem to be small but the difference is quite important; some other features have broader ranges, some others range in very small scales. $\endgroup$ – pedrosaurio Jan 17 '12 at 10:21
  • $\begingroup$ So, you are clustering different factors? Could maybe use some weight or transformation of values. $\endgroup$ – Nightwriter Jan 17 '12 at 10:45
  • $\begingroup$ No, I am comparing all continuous variables $\endgroup$ – pedrosaurio Jan 30 '12 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.