The objective of this study was to utilize machine learning techniques to analyze perioperative factors and identify blood glucose levels that can predict the occurrence of surgical site infection following posterior lumbar spinal surgery. Methods: A total of 4019 patients receiving lumbar internal fixation surgery from an institute were enrolled between June 2012 and February 2021. First, the filtered data were randomized into the test and verification groups. Second, in the test group, specific variables were screened using logistic regression analysis, Lasso regression analysis, support vector machine, and random forest. Specific variables obtained using the four methods were intersected, and a dynamic model was constructed. ROC and calibration curves were constructed to assess model performance. Finally, internal model performance was verified in the verification group using ROC and calibration curves. Results: The data from 4019 patients were collected. In total, 1327 eligible cases were selected. By combining logistic regression analysis with three machine learning algorithms, this study identified four predictors associated with SSI, namely Modic changes, sebum thickness, hemoglobin, and glucose. Using this information, a prediction model was developed and visually represented. Then, we constructed ROC and calibration curves using the test group; the area under the ROC curve was 0.988. Further, calibration curve analysis revealed favorable consistency of nomogram-predicted values compared with real measurements. The C-index of our model was 0.986 (95% CI 0.981-0.994). Finally, we used the validation group to validate the model internally; the AUC was 0.987. Calibration curve analysis revealed favorable consistency of nomogram-predicted values compared with real measurements. The C-index was 0.982 (95% CI 0.974-0.999). Conclusion: Logistic regression analysis and machine learning were employed to select four risk factors: Modic changes, sebum thickness, hemoglobin, and glucose. Then, a dynamic prediction model was constructed to help clinicians simplify the monitoring and prevention of SSI.