The study developed and validated a machine learning model to predict the risk of postoperative heart failure in patients undergoing non-cardiac surgery. Based on data from 489 patients (109 heart failure, 380 controls), a random forest (RF) algorithm was used, achieving high accuracy with an AUROC of 0.919 in training and 0.923 in testing, with external validation confirming an AUC of 0.878. Key predictors of postoperative heart failure were age, neutrophil-to-lymphocyte ratio, glucose level, INR, pulse, and serum creatinine (positively correlated), as well as serum albumin, MCHC, eGFR, and diastolic blood pressure (negatively correlated). The model includes 10 clinical variables that reflect age, inflammation, renal dysfunction, and hemodynamic instability. A web-based preoperative risk stratification tool was developed for clinical practice, allowing targeted interventions to improve perioperative outcomes. This multicenter study shows that machine learning can effectively help identify patients at higher risk of postoperative heart failure.