Why must features be scaled before running k-means or DBSCAN?

Last updated 11 November 2026

Both algorithms rely on raw distances. A feature with a large numeric range dominates the distance and effectively decides the clusters on its own, regardless of how informative it actually is.

  • Example: Take income (0–200,000) and age (0–100). A 1-unit income gap is trivial, yet the income axis is 2,000× wider, so clusters are split almost purely by income.

  • k-means: It minimizes squared Euclidean distance, so large-variance features dominate the objective quadratically.

  • DBSCAN: A single eps radius applies to all dimensions. Unscaled, that radius is huge on some axes and tiny on others, so no single eps makes sense.

  • Common choices:

    • StandardScaler: z-scores, the usual default.

    • MinMaxScaler: bounded range, but sensitive to outliers.

    • RobustScaler: median/IQR, better with outliers.

  • Caveat: scaling is itself a weighting decision. Equalizing variance assumes all features matter equally, so domain knowledge may justify deliberate reweighting.

[lang:python] from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler from sklearn.cluster import KMeans model = make_pipeline(StandardScaler(), KMeans(n_clusters=4, n_init=10)) labels = model.fit_predict(X)

  • https://medium.com/@karangore518/k-means-clustering-with-scaled-data-a-complete-beginner-friendly-walkthrough-c6138062b30a
  • https://github.com/Devinterview-io/k-means-clustering-interview-questions
  • https://dbscan.org/code/feature-scaling-dbscan/
All Clustering interview questions