Pre-Determining the Optimal Number of Clusters for k-Means Clustering Using the Parameters Package in R and Distance Metrics
Source abstract
Abstract
A drawback of the popular k-means clustering algorithm is that the number of clusters must be specified in advance, which can be challenging for users who may not have extensive experience with the methods involved (such as Elbow, Silhouette, and Hartigan, among others). To address this issue, we employed the n_clusters() function from the parameters package in R, which applies 27 clustering methods to determine the optimal number of clusters more easily. In addition, the Canberra, Euclidean, and Manhattan distance metrics were employed to identify similar data objects in the k-means clusters. These metrics were measured and compared in terms of accuracy, F1-score, precision, and recall via numerical studies employing 10 simulated and two real datasets. The results indicate that the n_clusters() function from the parameters package could accurately identify the correct number of clusters in all of the simulated and real datasets. In particular, the Hartigan and Tracew methods identified the correct number of clusters with an accuracy of 100%. These findings suggest that using the Hartigan or Tracew method can accurately pre-determine the correct number of clusters for the k-means clustering algorithm. Also, the findings show that the performances in terms of accuracy, F1-score, precision, and recall of both the Euclidean and Manhattan distance metrics were excellent, with both of them consistently outperforming the Canberra distance across all datasets.
Source: crossref · Quality: baseline
Affiliations
Department of Statistics, Faculty of Science, Khon Kaen University, Khon Kaen 40002, Thailand
Department of Statistics, Faculty of Science, Kasetsart University, Bangkok 10900, Thailand
References (61)
Show source-provided references
1. Clustering algorithms: A comparative approach10.1371/journal.pone.0210236 ↗
2. Review of clustering techniques in control system10.1016/j.procs.2020.06.032 ↗
3. Multi-view clustering: A survey
4. Multi-view learning overview: Recent progresses and future directions
5. Multi-view clustering via graph fusion
6. Multimodal deep learning: Techniques and applications
7. Algorithms for hierarchical clustering: An overview10.1002/widm.1219 ↗
8. Data clustering: 50 years beyond K-means10.1016/j.patrec.2009.09.011 ↗
9. Sculley, D. (2010, January 26–30). Web-scale k-means clustering. Proceedings of the 19th International Conference on World Wide Web, Raleigh, NC, USA.10.1145/1772690.1772862 ↗
10. Ester, M., Kriegel, H.P., Sander, J., and Xu, X. A density-based algorithm for discovering clusters in large spatial databases with noise. Proceedings of the KDD’96: Proceedings of the Second International Conference on Knowledge Discovery and Data Mining.
11. On spectral clustering: Analysis and an algorithm
12. Mean shift: A robust approach toward feature space analysis10.1109/34.1000236 ↗
13. The impact of neglecting feature scaling in k-means clustering10.1371/journal.pone.0310839 ↗
14. Data mining methods: K-means clustering algorithms10.34306/ijcitsm.v3i1.122 ↗
15. Clustering of patient disease data by using K-means clustering
16. Herman, E., Zsido, K.E., and Fenyves, V. (2022). Cluster analysis with k-mean versus k-medoid in financial performance evaluation. Appl. Sci., 12.10.3390/app12167985 ↗
17. K-means clustering algorithm applications in data mining and pattern recognition
18. Image segmentation method based on k-mean algorithm10.1186/s13640-018-0322-6 ↗
19. Ahmed, M., Seraj, R., and Islam, S.M. (2020). The k-means algorithm: A comprehensive survey and performance evaluation. Electronics, 9.10.3390/electronics9081295 ↗
20. Evaluation of stability of k-means cluster ensembles with respect to random initialization10.1109/TPAMI.2006.226 ↗
21. Arthur, D., and Vassilvitskii, S. (2025, May 11). K-means++: The Advantages of Careful Seeding. Available online: https://theory.stanford.edu/~sergei/papers/kMeansPP-soda.pdf.
22. Mahmud, M.S., Rahman, M.M., and Akhtar, M.N. (2012, January 20–22). Improvement of k-means clustering algorithm with better initial centroids based on weighted average. Proceedings of the 7th International Conference on Electrical and Computer Engineering, Dhaka, Bangladesh.10.1109/ICECE.2012.6471633 ↗
23. Cluster analysis of multivariate data: Efficiency versus interpretability of classifications
24. InitKmix—A novel initial partition generation algorithm for clustering mixed data using k-means-based clustering10.1016/j.eswa.2020.114149 ↗
25. An examination of procedures for determining the number of clusters in a data set10.1007/BF02294245 ↗
26. Humaira, H., and Rasyidah, R. (2018, January 24–25). Determining the appropriate cluster number using Elbow method for k-means algorithm. Proceedings of the 2nd Workshop on Multidisciplinary and Applications (WMA), Padang, Indonesia.
27. Gupta, U.D., Menon, V., and Babbar, U. (2010, January 9–11). Detecting the number of clusters during expectation-maximization clustering using information criterion. Proceedings of the Second International Conference on Machine Learning and Computing, Bangalore, India.10.1109/ICMLC.2010.47 ↗
28. Information theoretic clustering10.1109/34.982897 ↗
29. Silhouettes: A graphical aid to the interpretation and validation of cluster analysis10.1016/0377-0427(87)90125-7 ↗
30. Estimating the number of clusters using cross-validation10.1080/10618600.2019.1647846 ↗
31. Challenges in clustering high-dimensional data
32. Shi, L., Cao, L., Ye, Y., Zhao, Y., and Chen, B. (2024). Tensor-based Graph Learning with Consistency and Specificity for Multi-View Clustering. arXiv.
33. Enhanced latent multi-view subspace clustering10.1109/TCSVT.2024.3430041 ↗
34. Model-based clustering algorithms: A review and new developments
35. Fuzzy clustering and the challenge of determining the number of clusters in high-dimensional data
36. Estimating the number of clusters in a data set via the gap statistic10.1111/1467-9868.00293 ↗
37. K-means with three different distance metrics
38. Effects of similarity/distance metrics on k-means algorithm with respect to its applications in IoT and multimedia: A review10.1007/s11042-021-11255-7 ↗
39. Performances of k-means clustering algorithm with different distance metrics10.32604/iasc.2021.019067 ↗
40. Efficient k-mean clustering algorithm for large datasets using data mining standard score normalization
41. Dudek, A., and Walesiak, M. (2020, January 1–2). The choice of variable normalization method in cluster analysis. Proceedings of the 35th International Business Information Management Association Conference (IBIMA), Seville, Spain.
42. Parameters: A package to easily extract, summarize, and display model parameters
43. Comparative analysis of inter-centroid k-means performance using Euclidean distance, Canberra distance and Manhattan distance10.1088/1742-6596/1566/1/012112 ↗
44. Performance evaluation of k-means clustering algorithm with various distance metrics
45. Evaluation of clustering approach with Euclidean and Manhattan distance for outlier detection10.1063/5.0075570 ↗
46. Exploratory study on clustering methods to identify electricity use patterns in building sector10.1088/1742-6596/1343/1/012044 ↗
47. MixSim: An R package for simulating data to study performance of clustering algorithms10.18637/jss.v051.i12 ↗
48. Kanungo, T., Mount, D.M., Netanyahu, N.S., Piatko, C., Silverman, R., and Wu, A.Y. (2000, January 12–14). The analysis of a simple k-means clustering algorithm. Proceedings of the Sixteenth Annual Symposium on Computational Geometry, Hong Kong.10.21236/ADA458738 ↗
49. External validation measures for K-means clustering: A data distribution perspective10.1016/j.eswa.2008.06.093 ↗
50. Susmaga, R. (2004, January 17–20). Confusion matrix visualization. Proceedings of the International Intelligent Information Processing and Web Mining (IIPWM)’04 Conference, Zakopane, Poland.10.1007/978-3-540-39985-8_12 ↗
51. Diallo, R., Edalo, C., and Awe, O.O. (2024). Machine learning evaluation of imbalanced health data: A comparative analysis of balanced accuracy, MCC, and F1 score. Practical Statistical Learning and Data Science Methods, Springer.10.1007/978-3-031-72215-8_12 ↗
52. R Core Team (2025, March 11). R: A Language and Environment for Statistical Computing. Available online: https://www.R-project.org/.
53. Algorithm AS 136: A k-means clustering algorithm
54. The Hungarian Method for the Assignment Problem10.1002/nav.3800020109 ↗
55. Grötschel, M., Lovász, L., and Schrijver, A. (1988). Geometric Algorithms and Combinatorial Optimization, Springer.10.1007/978-3-642-97881-4 ↗
56. Automatic determination of the number of clusters in large-scale data
57. The application of cluster analysis in strategic management research10.1002/(SICI)1097-0266(199606)17:6<441::AID-SMJ819>3.0.CO;2-G ↗
58. Rosenberg, A., and Hirschberg, J. (2007, January 14–16). The SDbw cluster validity index. Proceedings of the Sixth International Conference on Fuzzy Systems and Knowledge Discovery, Tianjin, China.
59. Choosing the number of clusters in Κ-means clustering10.1037/a0023346 ↗
60. A robust cluster validation method based on statistical criteria for high-dimensional data
61. Improving cluster validity indices with statistical measures for complex datasets