Humans today live a lot longer than they used to. That’s great news, but as modern medical advances are giving patients second chances at living normal lives, end-of-life care continues to be a difficult thing to plan. Forecasting when someone will die is an extremely challenging and often uncomfortable thing, but Stanford researchers have trained an AI to be able to predict death with incredible accuracy, and it could revolutionize end-of-life care for patients who are reaching their ends.

The goal is to better match patient (and family) wishes with an accurate timeline of an individuals final months, weeks, and days, while affording them the opportunity to plan ahead for the inevitable. The work is titled Improving Palliative Care with Deep Learning, and it’s currently available online.

“Improving the quality of end-of-life care for hospitalized patients is a priority for healthcare organizations,” the researchers write. “Studies have shown that physicians tend to over-estimate prognoses, which in combination with treatment inertia results in a mismatch between patients wishes and actual care at the end of life.”

Inaccurate predictions from doctors can create unwanted consequences, such as patients spending their final days in a hospital ward rather than at home, surrounded by loved ones. By removing the human predictive element from the equation — which may be influenced by emotion and optimism — the algorithm takes a calculated look at the data and makes a call based on facts. The result is a much more accurate prediction of death that allows the patient and their family to plan for the best, most comfortable send-off.

The algorithm the researchers developed has been trained on over two million patient records. Using that data the AI can spot patterns that are simply invisible to a single doctor, and by drawing from those patterns it can make an educated guess as to when an ill patient will ultimately pass. When the algorithm is used to predict the passing of patients who are in palliative care (meaning they are not expected to live longer than 12 months), the system forecasts death with an astonishing 90 percent accuracy.

The way the AI goes about its predictions is quite complex, and while the researchers know how the system digests the data it’s being fed, the algorithm doesn’t have a simple way of explaining how it reaches its conclusions. Despite that, the digital brain is accurate enough in its predictions that the “how” is a secondary concern.