This is a retrospective study. Surgical site infection (SSI) is associated with adverse postoperative outcomes following total knee arthroplasty (TKA). However, accurately predicting SSI remains a clinical challenge due to the multitude of patient and surgical factors associated with SSI. This study aimed to develop and validate machine learning models for the prediction of SSI following primary TKA. This is a retrospective study for patients who underwent primary TKA. Chart review was performed to identify patients with superficial or deep SSIs, defined in concordance with the criteria of the Musculoskeletal Infection Society. All patients had a minimum follow-up of 2 years (range: 2.1–4.7 years). Five machine learning algorithms were developed to predict this outcome, and model assessment was performed by discrimination, calibration, and decision curve analysis. A total of 10,021 consecutive primary TKA patients was included in this study. At an average follow-up of 2.8 ± 1.1 years, SSIs were reported in 404 (4.0%) TKA patients, including 223 superficial SSIs and 181 deep SSIs. The neural network model achieved the best performance across discrimination (area under the receiver operating characteristic curve = 0.84), calibration, and decision curve analysis. The strongest predictors of the occurrence of SSI following primary TKA, in order, were Charlson comorbidity index, obesity (BMI >30 kg/m2), and smoking. The neural network model presented in this study represents an accurate method to predict patient-specific superficial and deep SSIs following primary TKA, which may be employed to assist in clinical decision-making to optimize outcomes in at-risk patients.