Can you teach an algorithm to know when you are most likely to die? One Stanford University research team is answering yes, reporting in a new paper that they have taught an algorithm to predict patient mortality with startlingly high accuracy.

Having an algorithm know your expiration date can sound like a dystopian concept, but the Stanford researchers said that they created the algorithm to benefit patients and doctors by improving the end-of-life care for ill patients. The researchers cited past studies that found the overwhelming majority of Americans would prefer to spend their last days at home if possible, but only 20% get that wish realized. Instead of getting to spend their final days at home, up to 60% of patients spend their last days in the hospital receiving aggressive medical treatments.

By creating a deep learning algorithm to predict patient mortality, doctors can better inform patients about their end-of-life options before it is too late, allowing more patients to get their spiritual and cultural final wishes met, the paper argues.

Research: There’s an algorithm that can predict patient mortality for critically ill patients

To train itself and make its predictions, the algorithm was given the electronic health records of about 2 million patients from two hospitals between 1995 and 2014. From there, the researchers identified around 200,000 patients suitable to be studied, and selected a smaller group of 40,000 patient case studies to be analyzed. The algorithm was then given the following marching order: “Given a patient and a date, predict the mortality of that patient within 12 months from that date.”

The results were highly accurate. Nine out of 10 patients died within the 3-12 month window the algorithm predicted they would die in.

Relax, doctors won’t be losing their jobs to machines

But the algorithm is not going to be replacing doctors Read More Here