To investigate high-risk factors for gestational diabetes mellitus (GDM) in early pregnancy through an analysis of demographic and clinical data, and to develops a machine-learning-based prediction model to enhance early diagnosis and intervention. A retrospective study was performed involving 942 pregnant women. A stacking ensemble (machine learning [ML]) was applied to demographic and clinical variables, creating a predictive model for GDM. Model performance was evaluated through receiver-operating characteristics (ROC) analysis, and the area under the curve (AUC) was calculated. Risk stratification was performed using quartile-based probability thresholds, and predictive accuracy was validated using an independent dataset. Significant predictors for GDM included age, pre-pregnancy body mass index (BMI; calculated as weight in kilograms divided by the square of height in meters), history of GDM, family history of diabetes, history of fetal macrosomia, education level, history of hypertension, and gravidity. These factors, which can be collected non-invasively at the first prenatal visit, formed the basis of a robust predictive model (AUC = 0.89). The model demonstrated a strong ability to exclude GDM, at a threshold of 28.53%. The machine-learning-based prediction model effectively identifies populations at high risk for GDM before invasive testing and oral glucose tolerance test, facilitating early clinical intervention and resource optimization.