Identification of rockmass class before construction is crucial to the safe and high-efficiency building of underground tunnels and has been a challenge for long water diversion tunnels. This paper is devoted to developing the LightGBM-based strategy for on-site rockmass class prediction in long tunnels from TBM construction data. The LightGBM-based strategy optimizes the input features and hyperparameters automatically by combining the tree-structured Parzen estimator (TPE), the light gradient boosting machine (LightGBM), and Shapley Additive exPlanations (SHAP) and establishes rockmass prediction models with data of various structures in 7505 TBM tunneling cycles in the Yinsong tunnel of 17.488 km long. The LightGBM-based strategy has an accuracy of 92% on the testing set, outperforms the random forest and support vector machines on the Yinsong tunnel data, and shows good generalization ability in the TBM7 tunnel in Xingjiang. The work contributes to the intelligent and efficient construction of long TBM tunnels.