BACKGROUND: Erectile dysfunction (ED) is a frequent complication following radical prostatectomy, significantly affecting patients' quality of life. Traditional predictive methods often struggle to capture complex nonlinear risk factors. This study aims to develop a machine learning-based model to improve ED risk stratification and guide personalized management. METHODS: A total of 1,147 prostate cancer patients were analyzed, among whom 285 (24.85%) developed postoperative ED. Univariate and multivariate analyses identified age, smoking history, Gleason score, prostate volume, T-stage, surgical approach, operative time, intraoperative bleeding, and PCT levels as independent risk factors (P <
0.05). Machine learning models, including XGBoost, Random Forest, Support Vector Machine, and k-Nearest Neighbors, were trained for ED risk prediction. Key predictors included advanced age, smoking history, Gleason score ≥ 8, prostate volume ≥ 40 ml, T-stage, laparoscopic-assisted surgery, and prolonged operative duration. RESULTS: XGBoost exhibited the highest predictive accuracy (AUC: 0.980 in training
0.960 in validation), outperforming other models. Calibration curves confirmed strong concordance between predicted and actual probabilities, while decision curve analysis demonstrated superior clinical utility, with XGBoost providing the greatest net benefit. Ten-fold cross-validation indicated stable performance (validation AUC: 0.9127 ± 0.0770
test AUC: 0.9592
accuracy: 0.9111), and external validation confirmed model generalizability (AUC: 0.84). SHAP analysis highlighted key risk contributors, enabling individualized risk assessment and targeted clinical interventions. CONCLUSION: The XGBoost model exhibited superior predictive performance and clinical applicability in assessing ED risk after radical prostatectomy, offering a robust tool for personalized postoperative management.