Artificial intelligence is proving to be a revolutionary tool across many industries, but the technology is having a particularly big impact when it comes to healthcare. Researchers are using AI to combat the flu, by building improved seasonal forecasts that inform the development of influenza vaccines, and the technology is already helping to diagnose rare diseases so that patients can get the treatments they need.

Now, scientists have found a new medical application for AI: predicting when a seriously ill patient admitted to the hospital will likely die.

In hospitals, palliative care teams are charged with improving the quality of life of gravely ill patients and making sure their final wishes are carried out. But clinicians sometimes don't refer their patients to these specialists because they believe their patients are better off than they really are.

Research shows that less than half of the 8 percent of hospital admissions who need palliative care actually receive it, says Kenneth Jung, a research scientist at Stanford University School of Medicine who helped develop the new AI algorithm.

This can have terrible consequences if the patient's health suddenly plummets, causing some people to spend their final days receiving aggressive treatments to extend life a few weeks when they'd rather spend that time with family. Studies have shown that approximately 80 percent of Americans say they would prefer to die at home, but 60 percent die in acute care hospitals, according to Stanford.

The new algorithm can predict if a hospital inpatient will die within 3 to 12 months (a window during which palliative care is thought to be most useful) with over 90 percent accuracy.

In the near future, health records of all hospital admissions could be screened by the AI, which would then flag palliative care teams about patients who may be near death. The specialists would review the records of those people and discuss with clinicians whether they could indeed benefit from palliative care.

In effect, the AI would help ensure that most severely ill patients are as comfortable as possible in their final months and receive the care that best reflects their preferences.

Get the mach newsletter. This site is protected by recaptcha

Deep Learning

The predictive model is an application of "deep learning," in which a computer isn't given predefined rules about the world but must instead learn to solve different tasks or make predictions by first studying massive data sets.

In this case, Stanford researchers used AI to parse the medical records of 160,000 deceased patients of Stanford Health Care and Lucile Packard Children’s Hospital who had varying illnesses (ranging from cancer to organ failure to neurological issues), medical histories, and disease severities.

Knowing the exact date of each patient's death, the AI searched the records for patterns indicative of advanced illness and encroaching death and assigned weights to the various pieces of medical information.

When tested on the records of another 40,000 patients whose deaths were withheld, the algorithm was able to correctly determine if the patient died within a 3- to 12-month window from a specific date nine times out of 10.

From left, Mitchel Todd, clinical social worker from Pathways Palliative Care, spends time with Sister Rosemary and takes her hand in his as they talk on may 28, 2010. New laws regarding hospice and palliative care in Colorado, are making them more accessible to people in their Denver homes. Kathryn Scott Osler / Denver Post via Getty Images file

David Hui, a palliative care specialist at the University of Texas who was not involved with creating the algorithm, said the technology “could help us care for patients better," but first needs to be tested at other hospitals and with more patients.

The algorithm is especially impressive because most conventional (non-AI) models can only achieve a death prediction accuracy of 70 to 80 percent, he says.

Extra Care

Research suggests doctors do routinely fail to refer patients for palliative care because they make inaccurate — and often overly optimistic — prognoses. But that's only part of the issue.

In some cases, Jung says, doctors may not make the referral simply because they're so focused on managing their patients' health issues that palliative care doesn't cross their minds.

And some clinicians don't refer because they believe in the "power of positive thinking" and don't want their patients to give up (a referral is sometimes seen as a death sentence), adds Bill Lukin, a palliative care physician at the University of Queensland in Australia.

The algorithm could help by identifying patients who are seriously ill and who may benefit from palliative care. With these results, specialists could then reach out to clinicians rather than wait for a referral.

Jung and his colleagues are now trying to determine how best to align the busy schedules of the healthcare workers so that they can discuss these identified patients in a timely matter.

Importantly, Jung says, the AI is not like a self-driving car, where human decisions largely take a backseat. Rather, it's more like vehicle proximity sensors that flag drivers' attention when necessary.

"It's not about replacing a doctor's judgment, ever," Jung says. "This really is about providing extra care."

FOLLOW NBC NEWS MACH ON TWITTER, FACEBOOK, AND INSTAGRAM.