When every bed counts: How AI and machine learning are improving the accuracy of length of hospital stays

A nurse checks a patient's vital signs in a hospital setting.

For hospitals, knowing how long a patient will stay in their care is central to delivering efficient and sustainable care. Being able to anticipate length of stay (LoS) allows hospitals to better manage capacity, resource allocation, staffing and overall costs. However, accurately predicting this key metric is challenging. Estimates largely depend on doctors’ judgment and supporting data that is often spread across different systems.

In his recent work on LoS modeling, IE University’s Dae-Jin Lee collaborated with a broader team to use artificial intelligence and machine learning to determine this metric more accurately. Using data from nearly 20,000 hospital admissions at Galdakao-Usansolo University Hospital in Spain’s Basque Country, they developed sophisticated models to forecast two mutually exclusive outcomes: whether a patient would be favorably discharged or whether their condition would deteriorate.  

The final model provided critical insight. It identified patterns that could provide doctors with the guidance they need to improve patient care, plot recovery trajectories, enhance scheduling, reduce bottlenecks and support resource planning. It also shone a spotlight on the growing role of AI and ML in making healthcare systems more patient-centered and efficient.

The ripple effects of LoS 

"When patients occupy beds longer than necessary, the ripple effects are far-reaching and potentially severe," Lee explains. Hospitals are interested in accurately predicting LoS because this metric has widespread effects on the entire system.

  • Delayed admissions: If beds are occupied unnecessarily, patients in need of urgent care, whether medical or surgical, face longer waiting times. Critical early warning signs can be missed and important procedures delayed.
  • Increased pressure on emergency departments: When wards are full and beds are unavailable, emergency departments are placed under strain. Patients who are not yet showing strong symptoms may be sent home too soon, only to return days later in a far worse condition, because staff simply don’t have the time or space to monitor them adequately.
  • Greater risk of hospital-acquired complications: Extended hospital stays raise the likelihood of hospital-acquired infections and complications. The longer a patient remains beyond the point when they could safely leave, the more exposed they become to the very environment meant to heal them.
  • Impact on staff workload and well-being: Busy wards result in clinical staff who are stretched across a greater number of cases for longer periods, increasing the likelihood of fatigue and the risk of error.
  • Overall costs: Prolonged stays consume resources, including beds, nursing time, equipment and medication, which places individual departments and whole hospitals under added financial pressure. 

Across Lee’s considerable dataset, patients whose conditions deteriorated spent, on average, almost twice as long in the hospital as those who were safely discharged. Their median LoS was nearly seven days, compared to under four for patients who recovered without complications. “This amounts to beds occupied and resources consumed, and in many cases, suffering that earlier intervention might have reduced,” he explains.

How fractured and inconsistent data disrupts prediction

Currently, clinical judgment is often the prevailing standard of care when it comes to forecasting LoS: an experienced physician assesses a patient and makes a call. However, studies cited in Lee’s paper found that ICU physicians are not always able to accurately predict LoS at the point of admission. While their experience and knowledge give them a good foundation, they tend to overlook a patient’s broader background, including previous hospital visits, chronic conditions and home circumstances. 

Of course, data exists to support their estimations, and doctors and hospitals depend on them heavily. Patients’ temperatures, heart rates, blood pressure, oxygen saturation levels (SpO2) and respiratory rates are all taken repeatedly throughout their stay. However, even where established protocols are in place, the urgent nature of hospitals means that these processes aren’t always followed as closely as they should be. And rather than provide the reliable detail that doctors need to improve the accuracy of their predictions, the available data can complicate matters. 

"Building a workable dataset from hospital records is often far from straightforward," Lee explains. "Records are often spread across different systems and are frequently incomplete. Some information sits with specific doctors. Other data only exists on paper and rarely makes it into a digital format. Nursing shift changes can also cause gaps in records. And, perhaps worst of all and despite the very best of intentions, monitoring isn’t continuous. Critical vital signs are both monitored and recorded on an irregular basis. Merging this fragmented, often incomplete data can be incredibly hard."

The research team found that across the vital signs they were working with, longitudinal data (information collected from the same subject repeatedly over time) was missing at strikingly high rates. Respiratory rate readings were absent in over 96% of longitudinal records, and SpO2 (one of the most clinically important indicators) was missing more than 55% of the time. Even after the team processed and cleaned up the data using their new approach, information about patients’ level of consciousness, whether they were alert, confused or unresponsive, was simply missing from the records in nearly two-thirds of cases.

A tech-powered solution

In their efforts to address some of these challenges, Lee and his team focused on the first 24 hours of a patient’s stay: the period in which the most important clinical decisions are made. Within this time frame, rather than using raw longitudinal vital signs, which are usually sparse and full of gaps, they converted these vital signs into summary statistics. This ensured they captured not just the last recorded temperature or SpO2, but the maximum, minimum, mean and variability of every vital sign across the admission window. This rigorous approach had never been applied to hospital LoS prediction before.

"Our process turned the messy, incomplete time-series data we had on hand into a form that our statistical models could actually work with,” he explains. “It also preserved the clinically meaningful information hidden in how a patient’s condition was trending." 

The team went on to compare five different imputation methods—techniques for making informed estimates about missing values. They found that one approach, known as MICE (Multiple Imputation by Chained Equations), consistently outperformed the others. The models themselves were built to respect the competing risk structure of the problem. Instead of asking how long a patient would likely stay, they were designed to simultaneously predict the two trajectories: safe discharge or deterioration. This distinction matters in practice because the clinical and operational responses to each outcome are completely different. 

Lee and his team then went on to test four types of models, comparing them against two clinical early warning tools already in common use: the National Early Warning Score (NEWS) and its modified variant, MEWS. The winner, by a clear margin, was a machine learning approach called a Random Survival Forest, which works by building hundreds of decision trees across the data and combining their outputs for a more robust collective prediction. 

"The advantage of this approach is its ability to handle large numbers of variables simultaneously," he explains. "It can detect complex, non-linear patterns in the data that simpler models would miss entirely." 

The results were striking. The best-performing model achieved a C-index (a standard measure of predictive accuracy) above 99%, across a prediction window stretching from 2 to 15 days ahead. The two vital signs that turned out to matter most were body temperature and SpO2: readings routinely collected in virtually any hospital setting in the world. And the model consistently and substantially outperformed both NEWS and MEWS, the tools that most hospitals currently rely on for early warning.

In practical terms, this means that Lee’s approach offers doctors a means to look at a patient on their first day of admission and generate a reliable forecast of which path they are likely to follow, and how quickly. Apart from the enormous value in providing adequate care for the patient concerned, the accuracy of these predictions also helps hospitals manage beds, staffing, resources and costs.

Bridging the gap between research and clinical application

When Lee’s team presented their findings to clinicians at the hospital, the doctors were especially curious about the practical applications. What would a solution like this cost to implement? How long would it take to measure its success? When would they start seeing results clinically and practically?

These are legitimate questions that don’t yet have definitive answers, largely because the model hasn’t been tested at scale in a live clinical environment. As Lee puts it, the bridge between academic research and practical implementation can be slow to build, but the effort is worth it. Ideally, he says, this testing should take place through a controlled pilot in a smaller setting, where the model’s effectiveness can be properly measured.

Lee’s hope is that the tool will give doctors all the information they need to see at a glance how the next two weeks might unfold: which patients are on track for discharge, which are at risk of deteriorating and where pressure points are likely to build. With this knowledge, doctors can make more informed decisions on resource allocation, discharge planning and patient flow management. The solution can help doctors identify patients at risk of prolonged hospitalization early enough to intervene, minimize complications and free up capacity.

However, Lee is clear about where AI tools should sit within clinical practice. "Algorithms such as this are not a replacement for clinical judgment, and anyone who believes otherwise is misreading what this technology can do," he says. "The real value lies in a doctor or nurse having a well-designed tool on hand that can provide them with timely and accurate data that they can act on. Our vision is for a multidirectional partnership between clinicians, data scientists, and AI and ML applications that helps to improve patient health and hospital efficiency."

Lee’s research makes it clear that hospitals are facing real challenges in LoS prediction, and that AI and ML interventions are capable of developing accurate and efficient solutions to these issues. The next step is to build the trust, infrastructure and institutional will to put predictive intelligence at the center of how hospitals are run.

  • A diverse group of people posing together in a professional setting.
  • A motivational phrase encouraging individuals to empower their entrepreneurial spirit.
  • A motivational quote encouraging innovation with a proactive mindset.
  • A message emphasizing the importance of cherishing diversity in people, mind, and experience.
  • This image features a motivational phrase emphasizing a humanistic approach in a stylish font.