Objective To explore the application of combined optimized machine learning algorithm for predicting the risk model of postoperative infectious complications of gastric cancer and to compare the accuracy with other algorithms, so as to find reliable biomarkers for early diagnosis of postoperative infection of gastric cancer. Methods The clinical data of 420 patients with gastric cancer at the Third Affiliated Hospital of Anhui Medical University from May 2018 to April 2023 were retrospectively analyzed and the patients were randomly divided into training set and validation set. Univariate analysis was used to determine the risk factors of postoperative infectious complications. Six conventional machine learning models are constructed using the training set: linear regression, random forest, SVM, BP, LGBM, XGBoost, and MGA-XGBoost model. The validation set was used to evaluate the seven models through evaluation indicators such as ACC, precision, ROC and AUC. Results Postoperative infectious complications were significantly correlated with age, operation time, diabetes, extent of resection, combined resection, stage, preoperative albumin, perioperative blood transfusion, preoperative PNI, LCR and LMR. Among the seven machine learning models, the MGA-XGBoost model performed best. Among the seven machine learning models, the MGA-XGBoost model performed best, with AUC of 0.936, ACC of 0.889, recall of 0.6, F1-score of 0.682, and precision of 0.79 on the validation set. Diabetes had the greatest influence on the internal structure of the model. Conclusion This study proves that the MGA-XGBoost model incorporating comprehensive inflammation indicators can predict postoperative infectious complications in patients with gastric cancer.