This study aimed to develop, validate, and evaluate machine learning (ML) algorithms for predicting Surgical site infections (SSI) and surgical site occurrences (SSO) after elective open inguinal hernia surgery. A cohort of 491 patients who underwent elective open inguinal hernia surgery at Fudan University Affiliated Huadong Hospital between December 2019 and December 2020 was enrolled. To create a strong prediction model, we employed five ML methods: generalized linear model, random forest (RF), support vector machines, neural network, and gradient boosting machine. Based on the best performing model, we devised online calculators to facilitate clinicians' access to a linear predictor for patients. The receiver operating characteristic curve was utilized to evaluate the model's discriminatory capability and predictive accuracy. The incidence rates of SSI and SSO were 4.68% and 13.44%, respectively. Four variables (diabetes, recurrence, antibiotic prophylaxis, and duration of surgery) were identified for SSI prediction, while four variables (diabetes, size of hernias, albumin levels, and antibiotic prophylaxis) were included for SSO prediction. In the test set, the RF model showed the best predictive ability (SSI: area under the curve (AUC) = 0.849, sensitivity = 0.769, specificity = 0.769, and accuracy = 0.769; SSO: AUC = 0.740, sensitivity = 0.513, specificity = 0.821, and accuracy = 0.667). Online calculators have been developed to assess patients' risk of SSI ( https://wuqian17.shinyapps.io/predictionSSI/ ) and SSO ( https://wuqian17.shinyapps.io/predictionSSO/ ) after surgery. This study developed a prediction model for SSI/SSO using ML methods. It holds the potential to facilitate the selection of appropriate treatment options following elective open inguinal hernia surgery.