The degree of rock mass discontinuity is crucial for evaluating surrounding rock quality, yet its accurate and rapid measurement at construction sites remains challenging. This study utilizes fractal dimension to characterize the geometric characteristics of rock mass discontinuity and develops a data-driven surrounding rock classification (SRC) model integrating machine learning algorithms. Initially, the box-counting method was introduced to calculate the fractal dimension of discontinuity from the excavation face image. Subsequently, crucial parameters affecting surrounding rock quality were analyzed and selected, including rock strength, the fractal dimension of discontinuity, the discontinuity condition, the in-situ stress condition, the groundwater condition, and excavation orientation. This study compiled a database containing 246 railway and highway tunnel cases based on these parameters. Then, four SRC models were constructed, integrating Bayesian optimization (BO) with support vector machine (SVM), random forest (RF), adaptive boosting (AdaBoost), and gradient boosting decision tree (GBDT) algorithms. Evaluation indicators, including 5-fold cross-validation, precision, recall, F1-score, micro-F1-score, macro-F1-score, accuracy, and the receiver operating characteristic curve, demonstrated the GBDT-BO model’s superior robustness in learning and generalization compared to other models. Furthermore, four additional excavation face cases validated the intelligent SRC approach’s practicality. Finally, the synthetic minority over-sampling technique was employed to balance the training set. Subsequent retraining and evaluation confirmed that the imbalanced dataset does not adversely affect SRC model performance. The proposed GBDT-BO model shows promise for predicting surrounding rock quality and guiding dynamic tunnel excavation and support.