Radical prostatectomy (RP) -- surgical removal of the prostate -- is the primary curative treatment for localized prostate cancer. While it effectively removes the tumor, the surgery carries a significant risk of damaging nearby nerves and blood vessels, often leading to erectile dysfunction (ED) as a permanent or long-lasting complication.
ED after RP results from injury to the neurovascular bundles (NVBs) that run along both sides of the prostate and control the nerve signals needed for erection. Even with nerve-sparing surgical techniques, mechanical manipulation, stretch injury, and disrupted blood supply to the penis can compromise function. Postoperative inflammation and tissue scarring further hinder recovery.
The impact of ED extends far beyond physical impairment. Studies show significantly higher rates of anxiety and depression among patients who develop post-RP ED compared to those who retain sexual function. Social withdrawal, relationship strain, and diminished self-esteem are common, making ED prevention and early intervention a priority in prostate cancer survivorship care.
Traditional approaches to predicting which patients will develop ED -- including logistic regression and clinical experience -- are limited by their linear assumptions and inability to capture complex interactions between dozens of contributing variables. Machine learning offers an alternative: algorithms that can model nonlinear relationships, handle high-dimensional data, and generate individualized risk predictions.
The study analyzed 1,147 prostate cancer patients from two hospitals affiliated with Nanjing Medical University in China. All patients underwent radical prostatectomy (either robotic or laparoscopic) with nerve-sparing techniques, performed by experienced senior surgeons. Of this group, 285 patients (24.85%) developed postoperative ED, defined by a score below 22 on the validated IIEF-5 questionnaire at six-month follow-up.
A comprehensive set of 27 variables was collected, spanning preoperative demographics (age, smoking, BMI), tumor features (Gleason score, T-stage, tumor size), surgical details (approach, operative time, blood loss), and postoperative laboratory markers including procalcitonin (PCT) and C-reactive protein (CRP), measured within 48 hours of surgery as indicators of inflammatory response.
Data from one hospital served as the internal training and validation cohort (split 70/30), while data from the second hospital provided an independent external validation set. Four machine learning algorithms were developed and compared: XGBoost (Extreme Gradient Boosting), Random Forest (RF), Support Vector Machine (SVM), and k-Nearest Neighbors (KNN). All models were evaluated on discrimination (AUC), calibration accuracy, and clinical decision utility.
To address the interpretability challenge -- often called the "black box" problem in machine learning -- the team used SHAP (SHapley Additive exPlanations) analysis to quantify each variable's contribution to individual predictions. This allows clinicians to see not just that a model predicts high risk, but exactly which patient-specific factors are driving that prediction, in what direction, and by how much.
Multivariate logistic regression identified nine independent risk factors for post-prostatectomy ED: age 65 or older, smoking history, Gleason score 8 or above, prostate volume 40 mL or more, T2 tumor stage, laparoscopic (vs. robotic) surgery, operative time above 270 minutes, limited intraoperative blood loss (below 100 mL), and elevated PCT levels (a marker of postoperative infection/inflammation).
Gleason score was the strongest single predictor in univariate analysis, with a Gleason score of 8 or higher associated with more than 15-fold higher odds of ED. Smoking history increased ED odds by over 8-fold, and prostate volume above 40 mL increased odds by more than 7-fold. These findings align with the biological mechanisms by which aggressive tumors require more extensive nerve-adjacent resection.
Surgical approach was highly significant: patients who had laparoscopic surgery had nearly 6 times higher odds of ED compared to those who received robot-assisted surgery. Robot-assisted systems offer 10x 3D visualization, multi-degree articulation, and superior precision in nerve-sparing dissection -- all of which translate into better preservation of erectile function-critical neural structures.
Elevated PCT (procalcitonin) in the 48 hours after surgery -- an indicator of early postoperative systemic inflammation -- was also independently associated with ED risk, suggesting that controlling post-surgical infection and inflammatory response may be relevant to sexual function recovery alongside surgical technique optimization.
Among the four machine learning models, XGBoost achieved the highest predictive performance across all evaluation metrics. It reached an AUC of 0.980 in training and 0.960 in validation -- meaning it correctly identified more than 96% of high-risk patients. In 10-fold cross-validation, XGBoost maintained a mean AUC of 0.9127 with an accuracy of 91.1%, demonstrating stable and reliable performance.
External validation on the independent hospital cohort yielded an AUC of 0.84 for XGBoost, confirming that the model generalizes well to new patients from a different institution. This is a critical test for real-world clinical applicability, as models that perform well only on the data they were trained on offer limited practical value.
Calibration curves showed that XGBoost's predicted probabilities closely matched actual patient outcomes -- what the model said was an 80% risk was observed approximately 80% of the time in reality. Decision curve analysis (DCA) further confirmed XGBoost provides the greatest net clinical benefit across a range of decision thresholds compared to the other models and to treating all or no patients.
By comparison, Random Forest achieved an external AUC of approximately 0.914, SVM 0.919, and KNN 0.924 in the test set, but all had lower overall accuracy than XGBoost (0.9111). KNN was particularly susceptible to high-dimensional data complexity, and RF's random subspace sampling occasionally missed critical feature interactions -- areas where XGBoost's gradient boosting approach excels.
SHAP (SHapley Additive exPlanations) analysis was used to open the "black box" of the XGBoost model and make its reasoning transparent for clinical use. The SHAP summary plot ranked features by their average impact on predictions, with larger prostate volume, Gleason score of 8 or more, T2-stage disease, long operative time, smoking, laparoscopic surgery, and advanced age all identified as the top positive risk contributors.
For four individual patients, SHAP force plots were generated showing exactly which factors pushed each patient's predicted risk up (shown in red) or down (shown in blue). Patient 1 had a predicted ED probability of 83%, driven primarily by advanced age, large prostate, laparoscopic surgery, and smoking history -- a case where multiple risk factors stacked together. Patient 2 was assigned only 1% risk, showing that the model can confidently identify low-risk patients too.
Patient 3 had a moderate predicted probability of 40%, with Gleason score and prostate volume as the key drivers -- a case where cancer aggressiveness was a primary concern even though other risk factors were lower. Patient 4 had a 21% predicted risk, where age, smoking, and long operative time contributed most, suggesting targeted counseling and shorter operative planning could help reduce risk.
These individualized analyses illustrate the potential for AI-powered risk tools to move beyond population-level statistics and deliver patient-specific guidance. Rather than applying a single threshold to all patients, SHAP-enabled models allow clinicians to understand the unique risk profile of each individual -- and to target interventions, such as optimizing surgical approach or preoperative lifestyle modification, accordingly.
The XGBoost model has practical applications at multiple stages of a patient's prostate cancer journey. Preoperatively, it can identify high-risk patients early, enabling counseling, lifestyle modifications (such as smoking cessation), and selection of optimal surgical technique. Intraoperatively, it informs decisions about nerve preservation extent. Postoperatively, it guides follow-up intensity and timing of ED interventions.
One of the study's most clinically actionable findings is the stark advantage of robot-assisted surgery over conventional laparoscopic prostatectomy for preserving erectile function. Robotic systems provide 10x magnified three-dimensional visualization, enabling surgeons to more precisely identify and protect the neurovascular bundles. The multi-articulated robotic instruments can perform more delicate dissection with less traction and nerve trauma than standard laparoscopic tools.
The mechanism linking larger prostate volume to ED risk is clarified by anatomical reasoning: bigger prostates displace the neurovascular bundles closer to surgical margins and may embed nerves within the capsule, making nerve preservation physically harder. Enlarged glands also require longer operative times, which in turn lead to greater local inflammation and edema that slow neurovascular recovery.
The authors note important limitations: the retrospective design carries selection bias risk, the IIEF-5 questionnaire is self-reported and subject to psychological and cultural factors, and objective measures like nocturnal penile tumescence testing were not included. Future validation in larger, prospective, multicenter cohorts with objective functional assessment will be needed before this model is ready for routine clinical deployment.