Groundwater resources in karst regions are abundant but vulnerable to contamination due to their complex geological characteristics, which complicate water management efforts. This study predicts groundwater quality in Nanning's karst region, where urbanization, industry and mining intensify pollution risks. The primary objective is to develop a predictive model for the Groundwater Quality Index (GWQI) using machine learning techniques, analyze key environmental drivers influencing groundwater quality, and map the spatial distribution of contamination to guide pollution control strategies. The study analyzed a dataset of 386 groundwater samples, evaluating four machine learning models—RF, GBDT, LR, and Ridge—for GWQI prediction. GBDT outperformed the other models, achieving an R
2 of 0.87 on the test set, which demonstrates superior accuracy and robustness. Feature importance analysis revealed that chemical enterprises, mining activities, and population density are the dominant factors influencing GWQI, with a combined contribution of 85.85% of the total variance. Precipitation and hydrological factors were identified as secondary influences. Spatial analysis indicated that most of the study area exhibited good water quality, although approximately 1% of the area exhibited significant point source pollution linked to industrial activities. The study further identified that over 1.5 million residents are at potential risk due to groundwater pollution, emphasizing the need for targeted mitigation strategies. This research highlights the critical role of machine learning in groundwater quality assessment and offers practical insights for environmental management. Key recommendations include stricter monitoring near industrial sites, optimized agricultural practices, and enhanced wastewater treatment systems to promote sustainable management of groundwater resources in karst regions.