AI is the umbrella term for all programs that mimic human intelligence in any way. Machine learning is a subset of AI. In machine learning, a model learns patterns from data. Supervised machine learning, also known as supervised learning, is the process by which a machine learns to make predictions based on previous data for which we already know the answer. The model is thus provided with examples that have the correct label or answer.
If we want to train a spam filter, we first need to feed our algorithm a large number of emails labeled as “spam” or “not spam.” Our algorithm then learns patterns by sifting through all those emails and can subsequently make an informed guess about new, unlabeled emails. You can also use supervised learning for tasks such as predicting home prices. You’ll need a list of homes that have already been sold, along with a number of characteristics such as size, the age of the home, energy efficiency rating, etc., and, of course, the price. The algorithm then learns from this data how much each of these characteristics is “worth” and uses that to predict the price of a new home.
Unsupervised machine learning is a type of machine learning where we want to recognize patterns in data without already knowing the answer. So we can’t use this to predict home prices, but we can use it, for example, to classify customer behavior. A well-known example of unsupervised machine learning is the Netflix algorithm, which gives you suggestions based on what other people who like the same shows are watching. Another example is the “Customers who bought this also bought” tab on websites like Amazon and Bol. These are simplified examples; recommendation systems can use various techniques.
Deep learning is a branch of machine learning that uses a “neural network.” This involves multiple layers of “neurons.” Each neuron in deep learning is a small computational unit that performs relatively simple calculations. Each neuron uses input from the previous layer of neurons, performs a calculation that often yields a result between 0 and 1, and passes this result on. You could use this, for example, to determine whether a cat is visible in a photo. Feed your machine a mountain of photos—some of which contain cats and some of which do not—provide the labels “cat” or “no cat,” and voilà. The algorithm adjusts the parameters of the neural network so that it becomes good at recognizing cats in photos.
Large language models, also known as LLMs, are themselves a part of deep learning. These include ChatGPT, GROK, and other AI systems in this category. Just like in deep learning, they use neural networks, but the major difference is the scale. Whereas a neural network that you could easily build yourself might have 100,000 parameters, ChatGPT now has more than 200 billion. The sheer size of the neural network requires an enormous amount of training and computing power, but the result is impressive. There are a few other factors involved, such as attention and tokenization, but the core of every LLM is a neural network. LLMs are trained in various ways; not every step in their training involves supervised learning.
Imagine you want to use this technology yourself. Here are the steps:
We have a problem to which we want to apply supervised learning—for example, predicting home prices. Based on the objective, we choose an algorithm that best suits our problem.
We collect data on homes that have already been sold. The more recent the sales and the larger the sample size, the better our algorithm will perform.
We train our algorithm on the majority of the data we already have.
We now apply our trained algorithm to the rest of the data to see if the predictions match actual home prices. If those test predictions are accurate, we’re satisfied and can start using our model. If the predictions are poor, we need more data, better data, a different algorithm, or a different training method.
Once you’ve chosen an algorithm, you’ll need training data to train your AI. In our examples of a spam filter, house prices, and cat recognition, we need appropriate training data. This includes, for example, emails where we already know in advance whether or not they are spam. For house prices, the training data becomes a bit more complicated, and for each house, we need to include a list of factors along with a price. For cat recognition, we need photos that either do or do not contain cats. The more training data we have, the better—as long as the data is also suitable and varied.
One of the most important steps in the entire process is collecting the right training data. The “garbage in, garbage out” principle explains what happens when we collect data incorrectly. To build a good model, we need highly varied data. When we train a model to recognize cats in photos, it’s crucial that we don’t just have photos with cats and photos without cats. We also want to include many photos in our training data that might show just a part of a cat, or that feature a puma, tiger, or other feline, or that include dogs, martens, and other small mammals, and so on. The borderline cases are the ones for which we want the most training data.
In the case of spam emails, the training data seems simpler, but there’s a lot involved there as well. There are so many different types of spam emails, and each type must be recognized. It’s not just the “free iPhone” emails that need to be caught, but also, for example, emails that masquerade as an invoice from a similar service you happened to use. Just had a new roof installed through dakvervanging.nl? Then it would be nice if your model also caught the fake email from dakvervanging.nl. There are many more malicious spam emails like this that we want to be protected from.
When it comes to home prices, the training data from our examples is the most challenging. There are many factors that influence a home’s total price: year of construction, lot size, home size, location, how well-maintained it is, how many bedrooms it has, whether it has a dormer window, whether it has a hot tub, and many other factors. Which factors can you easily measure? Do you even want to include all factors? How much value should we place on plenty of natural light in the house? How do we quantify “nice neighbors” in monetary terms?
Deciding what data to use and then collecting that data can easily be the longest and most expensive part of developing your AI. However, you don’t necessarily need a piece of paper proving you’re good at math.
Building a good AI is a daunting task. You start with a goal. What should the AI do? Based on that, you choose an algorithm that best fits your goal. Some examples include:
For example, do you want to build a spam filter for an email service? Then you’d use logistic regression. This is an algorithm that can classify messages as spam or not.
Do you want to develop an AI that can estimate home prices? Then you’d use a linear regression algorithm that can take various factors into account to predict a price. For house prices, we need data on houses along with their final sale prices. The linear regression algorithm then calculates how heavily each factor—such as square footage, number of bedrooms, and garden size—should be weighted. Based on these factors and the final price, the algorithm can “learn” how much weight to assign to each factor in order to predict a home’s price as accurately as possible.
Want to create an AI that can recognize cats in photos? Then you’ll use a convolutional neural network. Does that all sound very complicated? Fortunately, we don’t need to know exactly how every step of every algorithm works in order to use them.
An algorithm—what we often refer to as AI—is nothing more than a step-by-step plan, usually for a computer. This means that we tell the computer how to process the input we provide, namely the training data.
In the case of spam email detection, we store every word used in the Dutch language (and often parts of other languages as well) in a large column. That column—which we also call a vector—contains a binary 1 or 0 for each word in every email. “Yes” if this word appears in the email, and “no” if it does not.
Next, each word is assigned an initial value—for example, a random number for each word, or simply 1 for each word. If we assign a value of 1 to everything, that means we attach just as much importance to the word “free” as to the word “and,” even though, logically, we would expect spam more often with the word “free” than with the word “and.”
Next, we have the algorithm perform a simple sum over all the words in our dictionary, which we’ll assume for simplicity is 20,000:
Z = g₁w₁ + g₂w₂ + … + g₂₀₀₀₀w₂₀₀₀₀ + b
Here we see a final value Z for an email, which consists of the weight gᵢ for a specific word wᵢ that, in our example, starts at 1 for each word. We multiply that weight by 1 if the word appears in the email or by 0 if it does not. Then we add a bias b to the final value. The bias can shift the score. If no words contribute and the bias is 0, the probability of spam after the next step is 50%.
Now, for each email, we calculate the probability that it is spam using a function such as:
P = 1 / (1 + e⁻ᶻ)
With a function like this, the higher the Z-value, the greater the probability that the email is spam.
Since we started with a value of 1 for every word, we’re essentially just guessing whether an email is spam or not. Our AI makes a tremendous number of mistakes. However, we do know which emails are spam and which aren’t, and we include that information in our training data. Every time these mistakes are made, the algorithm looks at the values associated with each word and makes small adjustments. Was the word “free” used in an email where the algorithm decided it wasn’t spam, even though we specified that it was a spam email? In that case, the weight for the word “free” could, for example, be increased so that it carries more weight as a spam indicator. In another email, was the word “report” used in a message that the AI flagged as spam even though it wasn’t? In that case, “report” could, for example, be assigned a lower weight.
A model doesn’t get it right the first time. During training, it processes the training data multiple times and adjusts its settings to make better predictions. A complete cycle through all the training data has a special name.
Each cycle in which you run all the training data through your algorithm a single time is called an epoch. Contrary to what one might expect, it’s not better to let your model train for as long as possible. If you’re building a spam filter yourself, you’ll get better results with 50 epochs than with 10,000 epochs. The reason for this is overfitting.
These small changes in the values aren’t necessarily positive. Sometimes the model changes in the wrong direction and needs to be adjusted again in the next round. Contrary to what one might expect, you don’t want to run too many epochs. If you train your algorithm too often on your training data, it becomes very good at processing that training data. This can result in it performing poorly at recognizing new data that wasn’t included in your training data. This is called overfitting.
In the cat recognition example, it’s possible that after 100 epochs, an orange cat missing a paw wouldn’t be recognized as a cat, because your training data only included a few cats with a missing paw—and none of them were orange. After 10 epochs, the exact same algorithm might have recognized the cat, because it was a generally cat-shaped object in the photo with an acceptable color.
When training an algorithm, it’s common to split your training data into training, validation, and test sets, for example, in an 80%, 15%, 5% distribution. We then train our model on the 80% training data. We use the validation data during model development to check whether choices—such as the number of epochs—are working well. After each epoch, we test our model on the validation data to see how well this new version of the model performs on data it has never seen before. The model does not adjust its parameters based on the validation data, so this data is treated as “new” data. After our model has been trained, we perform a final test on the 5% test data to see if we’re satisfied with the result. That test data was not used to train the model. The reason we still use this test data is that the results on the validation data often influence our model: We select the parameters from the epoch that performed best on the validation data. After that, we test the model once more on the test data.
Understanding how your algorithm works is, of course, beneficial when developing AI. Understanding where your AI might make mistakes, how good your training data is, where there are still gaps, and what your AI isn’t good at—all of this becomes easier when you know exactly how the steps fit together. But a perfect understanding of all the math isn’t necessary.
If you choose an appropriate algorithm and can code it well, you’ll already be well on your way. Even for those steps, there are plenty of resources available these days. Collecting good test data, running your algorithms for the right number of epochs, and carefully analyzing where your training data or algorithm falls short will quickly lead to good results. Not everyone needs to know all the algorithms or even develop new ones.
So if you’re hesitant about developing your own AI and worry that it’s too difficult, don’t be afraid. Many of these algorithms have already been developed. You just need to take the step that’s always the hardest: the first step.