Developing nonlinear k-nearest neighbors classification algorithms to identify patients at high risk of increased length of hospital stay following spine surgery.



Spondylolisthesis is a common operative disease in the United States, but robust predictive models for patient outcomes remain limited. The development of models that accurately predict postoperative outcomes would be useful to help identify patients at risk of complicated postoperative courses and determine appropriate healthcare and resource utilization for patients. As such, the purpose of this study was to develop k-nearest neighbors (KNN) classification algorithms to identify patients at increased risk for extended hospital length of stay (LOS) following neurosurgical intervention for spondylolisthesis.


The Quality Outcomes Database (QOD) spondylolisthesis data set was queried for patients receiving either decompression alone or decompression plus fusion for degenerative spondylolisthesis. Preoperative and perioperative variables were queried, and Mann-Whitney U-tests were performed to identify which variables would be included in the machine learning models. Two KNN models were implemented (k = 25) with a standard training set of 60%, validation set of 20%, and testing set of 20%, one with arthrodesis status (model 1) and the other without (model 2). Feature scaling was implemented during the preprocessing stage to standardize the independent features.


Of 608 enrolled patients, 544 met prespecified inclusion criteria. The mean age of all patients was 61.9 ± 12.1 years (± SD), and 309 (56.8%) patients were female. The model 1 KNN had an overall accuracy of 98.1%, sensitivity of 100%, specificity of 84.6%, positive predictive value (PPV) of 97.9%, and negative predictive value (NPV) of 100%. Additionally, a receiver operating characteristic (ROC) curve was plotted for model 1, showing an overall area under the curve (AUC) of 0.998. Model 2 had an overall accuracy of 99.1%, sensitivity of 100%, specificity of 92.3%, PPV of 99.0%, and NPV of 100%, with the same ROC AUC of 0.998.


Overall, these findings demonstrate that nonlinear KNN machine learning models have incredibly high predictive value for LOS. Important predictor variables include diabetes, osteoporosis, socioeconomic quartile, duration of surgery, estimated blood loss during surgery, patient educational status, American Society of Anesthesiologists grade, BMI, insurance status, smoking status, sex, and age. These models may be considered for external validation by spine surgeons to aid in patient selection and management, resource utilization, and preoperative surgical planning.





Published Version (Please cite this version)


Publication Info

Shahrestani, Shane, Andrew K Chan, Erica F Bisson, Mohamad Bydon, Steven D Glassman, Kevin T Foley, Christopher I Shaffrey, Eric A Potts, et al. (2023). Developing nonlinear k-nearest neighbors classification algorithms to identify patients at high risk of increased length of hospital stay following spine surgery. Neurosurgical focus, 54(6). p. E7. 10.3171/2023.3.focus22651 Retrieved from

This is constructed from limited available data and may be imprecise. To cite this article, please review & use the official citation provided by the journal.



Christopher Ignatius Shaffrey

Professor of Orthopaedic Surgery

I have more than 25 years of experience treating patients of all ages with spinal disorders. I have had an interest in the management of spinal disorders since starting my medical education. I performed residencies in both orthopaedic surgery and neurosurgery to gain a comprehensive understanding of the entire range of spinal disorders. My goal has been to find innovative ways to manage the range of spinal conditions, straightforward to complex. I have a focus on managing patients with complex spinal disorders. My patient evaluation and management philosophy is to provide engaged, compassionate care that focuses on providing the simplest and least aggressive treatment option for a particular condition. In many cases, non-operative treatment options exist to improve a patient’s symptoms. I have been actively engaged in clinical research to find the best ways to manage spinal disorders in order to achieve better results with fewer complications.

Unless otherwise indicated, scholarly articles published by Duke faculty members are made available here with a CC-BY-NC (Creative Commons Attribution Non-Commercial) license, as enabled by the Duke Open Access Policy. If you wish to use the materials in ways not already permitted under CC-BY-NC, please consult the copyright owner. Other materials are made available here through the author’s grant of a non-exclusive license to make their work openly accessible.