Groundwater quality is measured through water sampling, and lab analysis. The eld-based measurements are costly and time-consuming when applied over a large domain. In this study, we developed a machine learning-based framework to map groundwater quality in an uncon ned aquifer in the north of Iran. Groundwater samples were provided from 248 monitoring wells across the region. The groundwater quality index (GWQI) in each well was measured and classi ed into four classes of Very poor, Poor, Good, and Excellent according to their cut-off values. Factors affecting groundwater quality, including distance to industrial centers, distance to residential areas, population density, aquifer transmissivity, precipitation, evaporation, geology, and elevation, were identi ed and prepared in the GIS environment. Six machine learning classi ers, including extreme gradient boosting (XGB), random forest (RF), support vector machine (SVM), arti cial neural networks (ANN), k-nearest neighbor (KNN), and Gaussian classi er model (GCM), were used to establish relationships between GWQI and its controlling factors. The algorithms were evaluated using the receiver operating characteristic curve (ROC) and statistical e ciencies (overall accuracy, precision, recall, and f-1 score). Accuracy assessment showed that ML algorithms provided high accuracy in predicting groundwater quality. However, RF was selected as the optimum model given its higher accuracy (overall accuracy, precision, and recall = 0.92; ROC = 0.95). The trained RF model was used to map GWQI classes across the entire region. Results showed that the Poor GWQI class is dominant in the study area and Good GWQI can be found in southwest. An area of Very Poor GWQI was observed in the north. Findings indicated that the distance to industrial locations is the main factor affecting groundwater quality in the area. The study provides a cost-effective methodology in groundwater quality modeling that can be duplicated in other regions with similar hydrological and geo-logical settings.