Accurately determining the uniaxial compressive strength (UCS) of rocks is crucial for various rock engineering applications. However, traditional methods of obtaining UCS are often time-consuming, labor-intensive, and unsuitable for fractured rock sections. In recent years, using Measurement-while-drilling data to identify UCS has gained traction as an alternative approach. To develop a method that can rapidly, efficiently, and economically estimate UCS across different rock types and engineering conditions based on while-drilling tests, this study compiles a comprehensive dataset from existing literature. The dataset includes drilling parameters and their corresponding UCS values, collected under varying lithologies, strength levels, drill bit types, and drilling conditions. Five machine learning models-multilayer perceptron (MLP), support vector regression (SVR), convolutional neural networks (CNN), random trees (RT), and long short-term memory networks (LSTM)-were trained and evaluated. Among these, RT demonstrated superior predictive performance, achieving a root mean square error (RMSE) of 15.851, a mean absolute error (MAE) of 4.449, a standard deviation of residuals (SDR) of 15.292, and an R² value of 0.959 on the test set. SVR also performed well, with an RMSE of 21.905, an MAE of 17.962, an SDR of 21.144, and an R² value of 0.922. While CNN and LSTM exhibited slightly higher errors, they showed better generalization capabilities across validation and test datasets. Furthermore, the models were validated on an unseen independent dataset, where RT achieved the best results, followed by SVR, while the other methods performed relatively poorly. This study indicates that RT and SVR demonstrate superior suitability for UCS prediction.