Algorithm

A set of instructions for completing a task or solving a problem.

At its most basic, an algorithm is simply ‘a set of instructions for completing a specific task or solving a specific calculation or problem.’ 

One of the most common everyday examples of an algorithm is a recipe: a set of step-by-step instructions that, when followed correctly, produce a specific dish, like a cake.

Yet, unlike the algorithm for turning flour, butter and eggs into a cake, in healthcare we can use algorithms to turn medical data into information about a patient’s condition. But how do you build an algorithm - a recipe - that can do this?

How to build an algorithm
Step 1: gather the data 

Almost all healthcare interactions are recorded in some way. For example, when you go to a doctor and get a new diagnosis (e.g. asthma) or a new prescription (e.g. an inhaler) it is recorded as a line in your electronic health record (EHR). Similarly, if you ever have an X-Ray or MRI scan, these images are stored. In both these cases the record of the healthcare interaction is ‘data.’ And it’s this type of data that becomes the raw ingredients for the algorithm. 

 

Step 2: curate the data 

Healthcare data is primarily designed to help clinicians manage the care of individual patients. If you are prescribed a new medication, it’s helpful for your doctor to know what medications you have taken previously and if you have ever had a bad reaction to a particular medication. The data was originally intended for humans to use, not organised in a way that makes it easy for machines to understand. So, before an algorithm can be trained on raw data (i.e. before the ingredients can be mixed together), it’s necessary to clean the data to make sure it is in the right format, and it is accurate. For example, it might be necessary to check whether dates are all recorded in the same format in different patient records (e.g. mm/dd/yyyy).

 

Step 3: train the algorithm 

Of course, a recipe is not just a list of ingredients and a set of instructions about what order to add the ingredients. It also specifies the exact amount or weight of the different ingredients needed. This is the same with an algorithm. Say, we want to create an algorithm that predicts whether or not a person will develop Type 2 diabetes within the next ten years. We have the raw ingredients – the data contained in medical records – and now we need to know how much each individual data point matters. For example, it might be that a person’s body mass index is very important when it comes to predicting the onset of type 2 diabetes, and so we need a lot of this ingredient (i.e., we need to give a lot of ‘weight’ to the BMI data point), but a person’s history of ear infections is not important. Researchers train the algorithm to understand which data is important to include and allow it to make the recipe over and over again until it gets it ‘right.’ 

 

Step 4: validate the algorithm 

It’s necessary for researchers to test if the recipe the algorithm has developed is correct (i.e. has it worked out which individual ingredients or data points it needs to reach its answer and how much or what weight it should give to each). To validate if it works, the researchers will give the algorithm completely new data that it has never seen before and see whether it can recreate the recipe perfectly (i.e. accurately predict the likelihood of type 2 diabetes developing in new, unseen patients).  

 

Step 5: test the algorithm 

The true test is not whether the same researchers can get the algorithm to produce the same results on new data, but whether it works correctly for different researchers or clinicians in different hospitals (i.e. can it accurately predict the likelihood of type 2 diabetes in a real GP’s practice). 

Those are the basic steps in designing and deploying an algorithm in healthcare. There are a wide range of recipes beyond predictions for example AI can be used for diagnosis, prognosis and treatment planning. But the same recipe must be followed, with special attention paid to the list of ingredients, so that results are specific and repeatable.

Despite how often it is used, the word ‘algorithm’ does not have a universally agreed definition. However, the most commonly accepted definition comes from the 1971 textbook Introduction to Computer Organization and Data Structures written by Harold Stone, which states that an algorithm is “a set of rules that precisely define a sequence of operations.” In medicine, such ‘algorithms’ have a long history, including Clinical Practice Guidelines and medical calculators, both of which set out a list of rules (or steps) for completing a particular operation (e.g. treating a specific condition or calculating BMI). 

These types of algorithms are not always ‘digital,’ they might be simple paper-based flowcharts or simple mathematical formulae that human clinicians are capable of mentally calculating. In the context of Artificial Intelligence; however, the word ‘algorithm’ typically refers to a complex set of instructions, written in a programming language, for completion by a computer. Although, there are many different ‘types’ of algorithm, all have the following characteristics: 

  1. Lack of ambiguity: each step in the algorithm has a clear purpose and can only lead to one type of output. 
  2. Specific inputs. 
  3. Specific outputs.
  4. Finiteness: an algorithm must be capable of ‘completing’ even if it has to run several times before reaching its conclusion. 
  5. Feasibility: an algorithm must be capable of completing its task using only the resources it has available.
  6. Deterministic: each time an algorithm is given the same input, it must produce the same output. 
  7. Effectiveness: each step in an algorithm must do some form of work necessary to complete the task.

Beyond these basic common characteristics, the various types of algorithms that fall under the umbrella heading of Artificial Intelligence (or the more specific umbrella of Machine Learning) vary considerably. Algorithm selection; therefore, depends on the strengths and weaknesses of a specific algorithm type and its suitability for a specific medical task (be that triage, classification, diagnosis, prognosis, risk prediction, treatment identification, drug discovery, or other).

Some of the most used AI algorithms for healthcare include: 
  • Naïve Bayes Classifier 
    This is a supervised* algorithm, primarily used for classification tasks. Derived from Bayes theorem, it’s trained to be able to predict the probability that a new ‘event’ falls into a specific class. It is most often used for diagnostic purposes (i.e. diagnosing the particular type of cancer in a patient). 
  • K-Means algorithm
    This is an unsupervised* algorithm, used for stratification or grouping tasks. It works by iteratively dividing a dataset into a prespecified number (‘k’) or non-overlapping ‘clusters.’ It can be used to classify patients into subgroups based on, for example, their genetic make-up. 
  • Support vector machine
    This is another supervised algorithm used for classification purposes. It can be trained to filter data into categories and is often used when dealing with incomplete datasets. This is one reason why it has had some success in drug discovery. 
  • Artificial neural network (ANN)
    This is an example of a ‘reinforcement learning*’ algorithm. ANNs are composed of layers of ‘nodes’ – an input layer, followed by one or more hidden layers, and an output layer. These layers, and the connections between the nodes (or neurons) are designed to mimic the working of the human brain, and sequentially filter information for classification or grouping purposes. ANNs have been used extensively for medical image recognition, and more recently for text (i.e. free text in EHR records) and speech recognition.  
  • Case-based reasoning (CBR) classifier
    This is an example of a ‘reasoning’ algorithm. When presented with a new case (for example a new patient), a CBR will look in its existing database (for example an EHR database) for an identical or similar case and use this to classify the new case. In healthcare, this has been used to diagnose patients based on similar symptom profiles and to recommend treatments based on prior success.  

* Definitions of the different types of machine learning. 

Type of machine learning Definition
Supervised learningAlgorithms are trained on labelled datasets.
Unsupervised learningAlgorithms cluster or classify unlabelled data.
Weakly supervised learning (sometimes referred to as semi-supervised learning)Algorithms are trained on datasets that are only partially labelled.
Reinforcement learningAlgorithms learn through trial and error.
Ensemble learningCombines multiple ‘types’ of algorithms to improve the overall performance of the resultant algorithm or model.

Ultimately, how well any of these algorithms perform when given a clinical or medical task depends on how well they are designed by human software developers. Research shows that the most ‘successful’ healthcare algorithms are: explainable, dynamic, precise, autonomous, fair, reproducible, and comprehensively evaluated.

An Owkin example

CHOWDER is a deep convolutional neural network algorithm developed by Owkin, trained using unsupervised learning capable of classifying histopathology slides. 

Further reading
  • Awaysheh, Abdullah et al. 2019. ‘Review of Medical Decision Support and Machine-Learning Methods’. Veterinary Pathology 56(4): 512–25.
  • Deo, Rahul C. 2015. ‘Machine Learning in Medicine’. Circulation 132(20): 1920–30.
  • European Parliament. Directorate General for Parliamentary Research Services. 2022. Artificial Intelligence in Healthcare: Applications, Risks, and Ethical and Societal Impacts. LU: Publications Office. https://data.europa.eu/doi/10.2861/568473 (June 10, 2023).
  • Information Commissioner’s Office. 2023. ‘Annexe 2: Algorithmic Techniques’. https://ico.org.uk/for-organisations/uk-gdpr-guidance-and-resources/artificial-intelligence/explaining-decisions-made-with-artificial-intelligence/annexe-2-algorithmic-techniques/ 
  • Loftus, Tyler J. et al. 2022. ‘Ideal Algorithms in Healthcare: Explainable, Dynamic, Precise, Autonomous, Fair, and Reproducible’ ed. Henry Horng-Shing Lu. PLOS Digital Health 1(1): e0000006.
  • Reisman, Y. 1996. ‘Computer-Based Clinical Decision Aids. A Review of Methods and Assessment of Systems’. Medical Informatics 21(3): 179–97.
  • Sidey-Gibbons, Jenni A. M., and Chris J. Sidey-Gibbons. 2019. ‘Machine Learning in Medicine: A Practical Introduction’. BMC Medical Research Methodology 19(1): 64.