InformIT

The Machinery of Learning

By and

Date: Feb 25, 2026

Sample Chapter is provided courtesy of Addison-Wesley.

Return to the article

Machines are good at pattern-matching, but they need to be taught what to look for.

Anonymous

Chapter 1, “Ten Breakthroughs That Made Generative AI Possible,” walks through the major breakthroughs that made generative AI what it is today. Each new step forward was accompanied by new concepts and new terms that described new possibilities, new algorithms, new architectures and their components. Although machine learning and GenAI are still plowing full steam ahead and inventing new words and acronyms almost every day, the field has matured enough that key foundational concepts and terms can be organized into a well-defined taxonomy.

GenAI builds upon a rich legacy of machine learning methods, and large language models (LLMs) leverage tools and concepts that have been refined over decades. The terminology is somewhat complex, as common words like model or learning often carry different interpretations in academic research than they do in the media. In addition, terms have evolved and taken on new significance as new breakthroughs have redefined their usage. Mastering AI vocabulary is essential not only to deepen your grasp of GenAI techniques but so you can better understand where and how different approaches are used. In addition to clarifying key terminology and taxonomy, this chapter introduces the main categories of machine learning techniques: supervised, unsupervised, and reinforcement learning.

Types of Learning

All machine learning techniques share the same basic idea: A computer program learns and improves by observing or measuring data. This learning is then used to make predictions when new data is presented to the program. The process involves three key elements that work together: a model, a form of learning (training) that is applied to the model, and actions on the model once it is trained (inference). The type, or family, of AI or machine learning that you are working with depends on the goal of this process. This taxonomy can be a bit complex because technical breakthroughs are sometimes remembered as their own family categories, even though they are simply more efficient ways of achieving some well-known goals. However, the most common way to organize the machine learning families is to distinguish between supervised learning, unsupervised learning, and reinforcement learning techniques.

Supervised Learning

AI techniques are about prediction and probabilities. Just as in real life, predictions with AI can be about things we don’t know or that we don’t know yet. For example, we might want to predict the future price of a stock, the time it would take for a car to stop after pressing the brake pedal, or whether an image (a collection of pixels for a computer) represents a cat or a dog. In each case, an expert could use knowledge and experience to come up with a prediction. This is also how a machine learns to provide an answer: We provide a large amount of training data, representing the parameters available to the expert, along with the correct answer for each case. The machine then learns the relationships between the parameters and the correct answer in the data. This type of AI technique is known as supervised learning.

In a way, supervised learning is about teaching a machine how to predict the right answer to a future question based on past training data. Intuitively, the concept is similar to how we learn many topics at school. We see multiple examples and end up forming mental rules that help us recognize patterns in order to link the description of a problem to the right answer. The more we study, the better we get at answering questions.

Many AI techniques detailed in this book use supervised learning either directly or as part of a more complex process. For example, generative adversarial networks (GANs, described in Chapter 5, “Neural Network Architectures”), the early versions of DALL-E, and LLMs that predict and then generate words in a sentence all use supervised learning in some ways.

Supervised learning is broken down into two classes of algorithms: regression and classification. Regression focuses on predicting a continuous value, such as the price of a stock or a house (and takes its name from a common statistical technique used in this context). The learning process is similar to how humans learn: by observation. When you were young, you likely learned to distinguish between cats and dogs by seeing many examples over time and learning “what makes a cat a cat.” If you work in real estate, you have seen enough houses for sale to be able to determine the likely value of a house after inspection. AI systems learn the same way: Once they have been exposed to thousands of examples, they internalize the measurable features that are characteristic of a particular structure. They can tell what pixels are necessary for an image to be labeled a dog, and they can guess the likely price of a house. The key difference between how humans do this and how AI does is scale. AI systems can process millions of examples, based on which they can detect even very subtle patterns that might escape human notice.

Classification, on the other hand, is about determining whether a given input belongs to one category or another. The outcome can be binary (for example, yes or no) or drawn from a larger set of predefined classes. Consider a medical scenario, with a diagnosis about a tumor. There are usually only two answers of interest: malignant or benign. The goal is not to describe the tumor in detail but to classify it correctly based on observed patterns.

Like all other supervised learning, classification relies on labeled data that trains a system to learn relationships between inputs and known correct answers. The system examines many examples where the correct category is already known (baseball statistics, different flower species, or spam versus legitimate emails) and learns to identify the patterns that distinguish between these categories.

Sometimes, classification does not involve just predicting which group something belongs to but also defining the boundaries between groups. Boundaries between groups can be thought of as the borders between countries on a map (although in AI these borders are typically in a high-dimensional space). Techniques for identifying these boundaries are often named for the mathematical approaches they use, such as support vector machines (SVMs), Gaussian mixture models (GMMs), or linear discriminant analysis. These terms and methods are common in the GenAI field and are often employed in voice and speech generation to find a pattern that most closely matches samples of a person’s voice or text.

Unsupervised Learning

In some cases, the answer to a problem is not known in advance, and a prediction cannot be easily made. For example, imagine a botanist with an extensive collection of flower images who wants to uncover patterns that could help categorize the flowers into families. In a different field, a bank processing millions of transactions each day might want to detect whether a specific credit card charge is normal or potentially fraudulent. Or consider a streaming service that wants to analyze a user’s viewing history to recommend the next best movie. In these situations, even a domain expert might struggle to give a definitive answer, and when the problem scales to millions of flowers, transactions, or users, relying on human experts quickly becomes impractical and costly.

Training a machine to uncover such patterns is the natural solution. Unlike with earlier cases, the goal here is not to learn a fixed relationship between inputs and a known correct answer. Often, there is no single “correct” outcome; there are only patterns that emerge from the data. For example, with fraud detection, unusual transactions might signal fraud, but what counts as “unusual” can vary significantly from one person to another. This type of analysis involves examining multiple parameters to identify common trends and then flagging data points that deviate from those norms, which are known in AI as outliers.

This branch of artificial intelligence is called unsupervised learning because it involves letting the machine find patterns and deviations from common properties; it does not teach the machine “the right answer.” The learning is unsupervised because it does not rely on a dataset that includes parameters associated with a label or a value that indicates the correct answer (for example, a group of pixels and a label like “cat” or “dog”). Rather, the instruction from the human to the machine is merely to form clusters of parameters that seem to have roughly the same values and indicate when some entries are away from the cluster. The machine forms these groups without further supervision.

Forming clusters and finding elements that go well together is fundamental in many generative AI techniques. For image creation, techniques examined in Chapter 5, like variational autoencoders (VAEs) and stable diffusion, leverage clustering to learn common patterns in shapes. In this way, they learn that “whiskers” are series of lines away from a common center (a nose or snout). Large language models also commonly use unsupervised learning when they learn patterns in text. For example, if we give a model like BERT a segment of a sentence that includes “Apollo 11 landed on the…,” it will guess “Moon.” This guess is possible because the model learned through clustering that the terms “Apollo 11” and “Moon” commonly appear in a single sentence. LLMs also use unsupervised learning to group together words and sentences that have the same general meaning, and so they are efficient at summarizing and finding synonyms.

Reinforcement Learning

In some cases, we need machines to learn, but neither supervised nor unsupervised learning is applicable. This happens when the machine needs to learn a skill, such as playing chess or picking up an object of variable shape from a conveyor belt. The goal is not to find patterns or describe relationships between some parameters and a label but to interact with an environment in near real time and make movement decisions that have consequences. Make the wrong move, and you lose the chess game or crush the object on the conveyor belt.

One approach to teaching machines proper skills is to program all possible moves for all possible scenarios. Researchers tried this idea in many ways in the 20th century, only to conclude each time that it was not feasible: There are too many possibilities, requiring too much memory and processing power to be realistic…and, of course, there is a high likelihood of “this corner case we did not think about” showing up at the most critical moment. A better approach (discussed as one of the key breakthroughs in Chapter 1) is simply to try to teach the machine the way we teach humans: Try things and keep (that is, remember and then prefer next time) those that work. This technique is called reinforcement learning because each interaction with the world reinforces the learning: The attempt works or doesn’t, or it is better, simpler, or faster than the previous one, for example. Reinforcement learning is particularly powerful because it does not require a preexisting dataset to train a model. The dataset is literally generated in real time as the model explores its environment. This mechanism allows continuous training of the model, and it also allows the model to find optimal outcomes that could never be discovered through a prepared dataset.

For example, suppose a car manufacturer wants to build a self-driving system. With reinforcement learning, the manufacturer can implement a pilot in a virtual car in a simulated landscape and reward the algorithm when useful actions are taken (such as avoiding a pedestrian or stopping at a red light). Negative actions (such as hitting virtual walls and people) cause the algorithm to lose points. Even without specific driving instructions, the algorithm will soon learn the rules of the road, such as speed limits, priorities at intersections, and efficient parking techniques. The manufacturer can then deploy the algorithm in a real vehicle with a human assistant driver, whose corrective actions also serve as reinforcement inputs.

This approach is so unique that reinforcement learning forms its own unique family of learning. This approach is extremely practical for highly interactive applications and complex decision-making scenarios, where preexisting datasets, especially optimized ones, may not exist. It is also useful as a complement to other techniques. For example, each time you provide feedback to an LLM (with the thumbs up or down button) or to an image generator (“I prefer this image” or you simply stop asking for refinements), your input is fed back into the algorithm through reinforcement learning to teach the machine what you (as a particular person or as a user in general) really wanted and to make the model more efficient for the next query of the same type. This technique is called reinforcement learning from human feedback (RLHF) and is examined in detail in Chapter 12, “Fine-Tuning LLMs.” Large cloud LLM companies have entire teams dedicated to using RLHF to teach their models to behave in ways that are socially acceptable (for example, do not teach people how to make bombs even if they ask, prefer positive answers, do not denigrate or insult users).

The Machine Learning Family Tree

The three families of learning we have discussed—supervised learning, unsupervised learning, and reinforcement learning—can be used to describe just about any technique in the field of machine learning, but you will find that many practitioners categorize the algorithms by goals instead of by learning families. Mapping the goals back to the families is useful to understand the technique that is most likely to be used by each approach, and Figure 2-1 provides such a map for the most common use cases.

FIGURE 2.1

Figure 2-1

Machine learning families, based on general goals

An AI project often combines two or all three types of learning. For example, unsupervised learning is used during the pretraining phase for LLMs, where the model learns language patterns and semantic relationships. Supervised learning is then often employed during fine-tuning, where the model is trained on labeled datasets to perform specific tasks, such as summarization or question answering. Finally, reinforcement learning is used in the final stages to align the model’s behavior with human preferences, helping it respond in ways that appear more helpful, safe, and “human-like.”

Beyond LLMs, some language processing tools use supervised learning to transcribe sounds into syllables and then use unsupervised learning to group common sound and syllable structures to train on speech recognition. An online recommender system (for example, the next movie suggestion in your favorite streaming subscription service) might use a mix of supervised data (for example, rating and reviews) and unsupervised data (for example, click patterns) to come to conclusions on common points and make recommendations. Such hybrid techniques are unsurprisingly called semi-supervised learning. With this type of learning, a model is trained on a dataset that contains both labeled and unlabeled data, with the goal of leveraging the unlabeled data to improve performance.

The organization of machine learning families is well established. Unfortunately, many sources list families of machine learning method according to the technique, algorithm, or equations they use rather than organizing them by their goal. Worse, some sources mix everything together and list algorithms and goals as different families within the same structure. This type of subdivision can be confusing because different algorithms might achieve the same goal, making the taxonomy ambiguous. Some of the most confusing subdivisions also try to cram field names (like “natural language processing”) into the same structure. The result is a taxonomy of AI families that make the algorithms appears as a random collection of goals, techniques, and fields but that are listed as generally equivalent. With such mixing, an AI technique may appear with different names or in different “families,” as if the algorithm and its field of application have to be linked with a special name.

In this book, we have tried to avoid such confusion. However, you will see in the other chapters of this book that in many cases, a technique implements a particular variant of one of the three families, and it will be useful to get familiar with these variants. Figure 2-2 provides the names of the learning families, their goals, and some popular algorithms in each category.

FIGURE 2.2

Figure 2-2

Machine learning families and their key techniques

Supervised learning techniques within the regression subfamily tend to be organized based on the type of relationships they explore. For example, when the relationship between an input and an output is directly proportional, it is referred to as linear regression. However, if the relationship is more complex, such as when modeling the link between many intricate parameters and a single outcome in the real world, it is called non-linear regression. GenAI techniques use both.

In some cases, regression techniques do not strictly involve numeric data but also use categorical data to guide decision-making. Consider predicting outcomes based on questionnaire responses with multiple-choice questions. In this scenario, the algorithm builds a tree structure by mapping all possible answers, allowing it to predict the most likely outcome based on a few key responses. This approach to predictive modeling based on tree structures is known as a decision tree. Trees are less common in GenAI. They are important for many other applications of machine learning, such as spam detection, risk assessment, loan approvals, and more.

The classification branch of supervised learning has a richer vocabulary than the regression branch, partly because there are many mathematical methods for determining whether two elements belong to the same category. One common approach is probabilistic learning, which relies on probability theory to make informed guesses about classification. This approach makes assumptions about the structure of a group and evaluates whether new data fits those assumptions. The field draws from the work of the 18th-century statistician Thomas Bayes, and many modern probabilistic techniques bear his name, such as Naïve Bayes, Bayesian networks, and Bayesian optimization. Although the math dates from the 18th century, the AI methods leveraging them remain highly relevant in today’s GenAI landscape.

In a supervised learning context, Naïve Bayes is often used to classify credit card transactions as safe or fraudulent. Probabilistic models are also widely used in generative applications, where the system doesn’t just classify existing content but generates new content based on patterns it has learned.

For example, consider a model trained on a large collection of short stories. Each story includes variables like genre, setting, main character type, plot arc, and ending style. A Bayesian network trained on this data can uncover how different variables interact. When asked to generate a new story, the model might determine that if the genre is “mystery,” there is a high probability that the main character would be a detective, and the plot would center around solving a crime. If the genre is “romance,” different narrative elements emerge with higher probability. Such inferred relationships form the essence of many generative models. The model does not just reproduce a story it was trained on; it assembles a new one by drawing from a network of statistically likely choices. The outcome may feel creative, but it is based on learned probabilities.

This probabilistic approach also extends beyond text. In image generation, if a character is described as wearing sunglasses, the model will infer with a high probability that the outdoor scene should be sunny. By learning such latent relationships, generative systems can produce outputs that feel coherent, even humanlike, without ever being explicitly programmed to do so.

Bayesian methods are not the dominant architecture behind modern LLMs or diffusion models, but they embody a critical concept in GenAI: Generative models rely on internal representations of patterns and probabilities.

What Is a Model?

Regardless of the goal or the technique used, machine learning involves algorithms that learn from data how to reach the right conclusion. When AI systems are developed, designers need to represent the relationship between the input data provided to the program and the output it produces. This relationship is known as the model. The learning element of the process depends on the task at hand. In all cases, there needs to be a human to design the learning program: what the program should look like, what the machine should learn, and how the learning should happen. To build this structure, AI scientists need to represent in some way the expected relationship between the data that will be provided to the program and the output expected from the program. More concretely, an AI/machine learning model is a mathematical representation (or program) that identifies these patterns and relationships, enabling it to make predictions or decisions without needing explicit instructions. The model ingests data, processes it based on the learned relationships, and outputs predictions, classifications, or representations.

Models are trained on data to optimize their internal parameters. These parameters are numeric values that become accurate over time as the model goes through successive training cycles. The type of model and its learning method are chosen based on the task, such as classification, regression, or content generation. In some cases, the relationship between input and output can be expressed mathematically, like a simple linear equation. In other cases, it might be captured in code. Both serve the same purpose: They represent a logical method that allows the model to connect data to decisions and, ultimately, predict an outcome.

For example, imagine that you are working for a road safety organization, and your goal is to estimate how long it takes a car to stop after a particular curve on the road. Many variables influence stopping time, such as speed, weight, and road conditions, but let’s start by modeling the relationship between just one set of variables: the car’s initial speed and its stopping time. This is a regression problem: Your goal is to predict a continuous value (time to stop). If there is a direct, proportional (linear) relationship between speed and stopping time, the model might use a linear equation, like this:

y = ax + b

where:

x is the input variable (car speed)

y is the output variable (stopping time)

a is the slope (how much y changes for each unit increase in x)

b is the intercept (the value of y when x = 0)

In many real-world examples, the value of b might be zero (because, for example, a stopped car does not need any time to stop). In other cases, such as sales forecasting based on advertisement investment, the intercept could reflect baseline sales even when advertising spending (x) is zero. Each data point you collect, such as car speed and its corresponding stopping time, helps the model learn the shape of this relationship. When plotted, the curve is often visualized as a line: simple, interpretable, and in this case useful for building intuition about how linear regression works.

In the real world, most problems involve far more than one input variable. For example, stopping typically involves many factors, such as weather conditions, tire quality, and the weight of the car. This creates a multidimensional problem, with each input variable referred to as a feature. The features are usually represented as x1, x2,…xn, each with its own coefficient (the number in front of the variable). The model equation generalizes to:

y = a1x1 + a2 x2 + … + an xn + b

The process of deciding which features to include and which ones to ignore is known as feature engineering. It is a critical step in supervised learning. More features can make the model more powerful and accurate, but they also make it more complex, harder to interpret, and slower to train. As in many other parts of AI, deciding the number of features for a particular problem is often a balancing act.

Of course, not all models are linear. Many models are nonlinear or even composed of multiple sub-models or equations. This complexity arises when the output is the result of multiple interacting factors. Imagine testing stopping times on a frozen lake. Some cars might skid as the tires lock, and stopping time could be affected by brake pad pressure, tire heat, car weight, and how the ice responds to heat and pressure. The model might need to calculate intermediate values like heat buildup or skid length before combining them into a final output. In such cases, the model could consist of multiple equations, some feeding into others. This is where composite models and deep learning architectures come into play, with layers of computations leading from input to output.

How Models Are Trained

In the examples we have explored so far, models include parameters, such as a, b, or a1, a2, etc., which are symbolic placeholders for real numeric values. The primary goal of machine learning is to learn these values during a process called training. Training involves teaching a model to recognize patterns, make predictions, or generate new content based on a dataset. It involves iteratively adjusting the model parameters to optimize its performance on a specific task to minimize the difference between the model’s predictions and the actual outcomes.

Training involves feeding a large set of data (called the training set) into the model. In the case of modeling how long it takes a car to stop, the training set would be a large collection of observed value pairs {speed, time to stop}, and training would involve asking the computer to find the best parameters that represent the relationship between the speeds and the times to stop.

This learning phase is somewhat like a brute-force process, where the program tries a large set of numbers until it finds the “least bad” values for the parameters to model the data. We use the expression least bad because in most cases, the training phase does not find perfect numbers: It simply finds the best numbers that can be inferred from the training data. In the car example, different cars with different brakes, tires, or shock absorbers may take different times to come to a complete stop, even when starting from the same speed, which means the final parameters will have a margin of error. They will represent the behavior of most of the cars. The parameters may not be perfect for each and every car, but they are the best ones to model the training set.

In practical terms, the real world is “noisy”: Unknown or unmeasured variables influence the outcomes of experiments. These hidden variables are not included in the dataset because they are unknown or nearly impossible to measure. As a result, the experimenter only records observed variables—variables that are known and accounted for, such as speed. Because of this limitation, a model typically cannot learn its parameters perfectly. Instead, it estimates parameters (such as coefficients a and b) that work best on average, minimizing the gap between the predicted outcomes and the actual measurements. The model then outputs a likely, calculated value of y that is close to, but rarely exactly the same as, the real-world value of y observed during the experiment.

The goal of the model is not to match every individual (and potentially noisy) data point but rather to find the general relationship between inputs and outputs. For example, even if the stopping time of a car varies slightly due to unmeasured conditions, the model still allows you to predict the approximate time the car will take to come to a full stop. Naturally, the more observed variables your model includes, the more accurate its predictions are likely to be.

A measurement of the difference between the calculated (predicted) y and the real value is called the loss. This loss can be determined in a few different ways, but it is generally represented by a loss function. The goal of the training phase is to continually refine the parameters in a way that minimizes loss, allowing the model to accurately reflect the input and output relationship.

The details of how the loss function is minimized depend on the type of machine learning technique that is in play. However, all training phases have some common traits. In general, the larger the training set, the better the model. This is because the presence of many noisy data points tends to average out over time, allowing the relevant patterns to emerge more clearly. It is a principle we encounter in everyday life. For example, if you show someone just five pictures of cats, they might conclude that the defining traits of a cat are simply fur and pointy ears. But those features also describe many dogs. With more examples, the distinctive features of cats become easier to identify.

Similarly, if someone tries to cook a dessert, such as crème brûlée, after tasting it only twice, their results are unlikely to be great. But after many tastings, they start to pick up on the dessert’s defining characteristics and notice that it is not just sweet and creamy but also has a caramelized crust, a hint of vanilla, a custard texture, and so on. Machine learning follows the same principle: More data allows the model to distinguish meaningful traits more accurately.

Larger and varied datasets are generally more desirable, but a larger training set also comes with a downside: It takes longer to train, which could mean increased cost (in terms of GPU, power, the cost of waiting to see if the training worked, and so on) The training phase is often a balancing act between the desired accuracy of the model (“as good as possible” is usually too vague) and the expected training time (“as fast as possible” is also too vague). There are many tools dedicated to estimating the training time and measuring the accuracy of a trained model.

Training, Validation, and Test Datasets

Training a machine learning model is a process of exposing it to examples so it can learn how inputs relate to desired outputs. This learning phase typically involves feeding the model a large dataset, called the training set, and letting the model adjust internal parameters to minimize error.

Rather than train on all the data at once, most models learn in batches—small groups of data points that are processed together. This progressive process limits the amount of memory needed to train, and it also allows the model to update itself incrementally and refine its performance in steps. A full pass through the training set is called an epoch, and training often involves many such passes.

But models are not judged solely on how well they perform during training. A good model must also generalize, which means it should work well on data it has not seen before. To this end, a dataset is typically split into three parts:

After the training phase, the next step is to assess how well the model performs by testing it against the validation set. This step helps evaluate the model’s accuracy during development and allows the model designer to adjust parameters that help optimize performance, if needed. The model has never seen the validation data before, and the validation phase simulates how the model might perform on new, unseen inputs.

In most cases, the model will perform slightly worse on the validation set than on the training set. If the difference in performance is small (and you define what qualifies as “small enough”), then the model can be considered acceptable for use. However, if the performance gap is large, the model may not generalize well and likely needs improvement. At that point, you discard the underperforming model, adjust aspects of its design, and train a new version using the same training set. You then evaluate the updated model against the validation set. You repeat this process until you are satisfied with the results or until you decide that the model cannot be improved further.

Figure 2-3 shows this iterative cycle of training and validating.

FIGURE 2.3

Figure 2-3

The training cycle

Once the performance of the model on the validation set is deemed acceptable, the model is likely to be evaluated one final time before production, using the test set, which is a separate portion of the data. Like the validation set, the test set has not previously been used during the training, which means that from the model’s perspective, it is fresh raw data. If the model has been trained properly, its performance on the test set should be comparable to its performance on the validation set.

Dividing a dataset into training, validation, and test sets allows you to measure how well the model is learning and whether it is likely to perform reliably in the real world. If a model performs well on training data but poorly on validation or test data, it may not be learning meaningful patterns but only memorizing specific examples. We will revisit this challenge, known as overfitting, later in the chapter.

Once a model is finalized, it can be deployed and used to make predictions on entirely new real-world data. This stage, where the trained model receives inputs and produces outputs, is called the inference phase.

Inference Models

In AI and machine learning, inference is the step where the model is fully trained and deployed, when it applies the relationships that were learned from the training phase. It allows the model to make predictions or classification on new data it has not seen before, allowing it to infer an output result solely based on the learned parameters and a given input.

Once a model is deployed for inference, it does not typically receive further training. However, it is still useful to continually monitor how the model is performing compared with real-world observations. When differences become noticeable, further training, fine-tuning, or other adjustments to the model may be necessary. Keeping an eye on the accuracy of your model is thus a central part of the AI development cycle.

While not all AI models are generative, almost all of them rely on this same training–inference cycle. However, the complexity of the model, the size of the dataset, and the sophistication of the outputs differ from one model to another.

How to Measure Model Accuracy

Accuracy depends greatly on the type of task. In the example of predicting the braking time of a car, you do not expect the model to be perfect (because the world is noisy). However, you want the model-predicted outputs to be as close as possible to the actual observed values. Consider a variation where the model is designed to predict whether a car has enough time to stop before reaching a stop sign. The difference between the model prediction and the real-world stopping times can be measured using the training data. This difference gives you an estimate of the model’s accuracy or, more precisely, its error. For example, you might find that the model predicts stopping time with an average error of ±5% compared to the actual observed times. In other cases, the model may be used for a classification task, such as predicting whether a car should issue a driver alert based on current speed and driving conditions. For example, imagine a system that monitors the car speed, distance to the vehicle ahead, lighting conditions, rate of deceleration, weather conditions, and so on. Its goal is to classify the situation as either “safe” or “issue alert.” The model might predict: “At this speed and following distance, is there a high likelihood of needing to warn the driver?”

The model accuracy refers to how often it correctly makes this decision. If it predicts that an alert should be issued, did the situation actually warrant one, or was it a false positive? If the model has only 50% accuracy, it is no better than flipping a coin: It fails to provide any meaningful guidance. In contrast, an 80% accuracy means the model is right four times out of five but still makes errors in 20% of cases. Depending on the consequences, this may or may not be acceptable. For a life-critical system like collision avoidance, that error rate might be too high. But for noncritical systems, like adjusting cruise control behavior or suggesting breaks during long drives, 80% might be considered acceptable, especially compared to random guessing.

Ultimately, the acceptable level of accuracy depends on the context and the cost of being wrong. In high-risk scenarios, even a seemingly good model might not be reliable enough without further fine-tuning or safeguards.

When training an AI model, you may achieve a higher accuracy rate, but the importance of that accuracy depends on the consequences of being wrong. If the model occasionally issues an alert when none is needed (a false positive), the result may be mild annoyance for the driver. Perhaps they slow down unnecessarily or dismiss the warning. But if the model fails to issue an alert when a real hazard is present (a false negative), the consequences could be severe and result in a collision with another vehicle or an obstacle. This issue highlights a core principle in AI: Acceptable accuracy depends on the cost of mistakes.

The accuracy of a model must be measured holistically and not just on the training, validation, or test sets alone. It must also be measured on new data during the inference phase once the model is deployed in the wild. One common issue in the development of AI projects is developing a model that is too simple and fails to capture important relationships in the data (for example, trying to fit a straight line to data that actually follows a more complex curve). Intuitively, this is like trying to explain a complex abstract subject in the language of a 5-year-old. You might get the essence of the idea across, but you will miss a tremendous amount of detail. This situation is known as underfitting. An underfit model typically shows poor accuracy across the board—on training, validation, test, and real-world data—making it a weak predictor.

At the other end of the spectrum, you might overcompensate by tweaking your model with so much detail that the model tries to match the training data too closely, capturing noise and irregularities that are not part of the underlying pattern. This is called overfitting. While the model may show high accuracy on the training set, and sometimes even on the validation and test sets, it often performs poorly when faced with new data it has not seen before during inference.

An ideal model strikes a balance. It generalizes well, producing similar accuracy across validation, test, and real-world data. In other words, a good model does not just fit the training data; it learns the underlying patterns well enough to generalize reliable predictions. Figure 2-4 illustrates overfitting, underfitting, and fitting that is just right.

FIGURE 2.4

Figure 2-4

Overfitting, underfitting, and “just right” lines in linear regression models

How accurate a model needs to be often touches fields beyond strict machine learning. For example, imagine a company that installs an app on employees’ phones to detect inappropriate content and automatically file a public police report when it finds such content. In this case, even 95% accuracy could be problematic because it means that for every 1,000 reported violations, 50 would be completely innocent. Is such a number acceptable? The answer depends on corporate policy and culture, which are elements that are beyond the field of AI and machine learning.

Hyperparameters

Throughout this chapter, there has been much discussion about model parameters. The job of the machine is to find the best values for these parameters; the parameters should result in predictions that are as close as possible to the real observed values across the training set. However, there is another dimension to model performance that needs to be discussed: hyperparameters.

Unlike parameters, which are internal to the model and are adjusted to minimize loss during training, hyperparameters are external configuration settings that influence how well the model performs. For example, after each batch or epoch during training, the model updates its parameters slightly to reduce the loss. The size of this update (how much the model tries to adjust itself to reduce error during the next epoch) is controlled by a hyperparameter called the learning rate.

A high learning rate lets the model adjust quickly but risks overshooting the optimal values and getting stuck in a cycle of jumping around without minimizing the error function. A low learning rate will give you better precision but could slow down training and increase computational cost, or it could get the model stuck in a local minimum, where it essentially loses sight of the big picture of what it is trying to accomplish. Choosing the right learning rate is something of a trade-off. It may take many adjustments to find the optimal learning rate if doing so by hand, but the job can also be made easier by optimization algorithms, which try to guess the optimal learning rate. Such methods include Bayesian optimizations and Grid Search, among others.

Learning rate is one of many hyperparameters, and each algorithm may have its own unique hyperparameters, such as batch size, number of epochs, or even the model’s structure. What you need to remember is that hyperparameters control how the model learns, not what it learns.

Table 2-1 provides a comparison of parameters and hyperparameters.

Table 2-1 Comparing Parameters and Hyperparameters

Aspect

Parameter

Hyperparameter

Definition

Internal values learned from data during training

External configuration settings

Purpose

Defines how the model makes predictions

Controls how the learning process unfolds

Examples

Weights (such as a and b in y = ax + b), bias terms

Learning rate, batch size, number of epochs, model depth

Set by

Learned automatically by the model during training

Manually defined by the user or optimization algorithm

Affected during training

Yes; updated iteratively to minimize the loss function

No; remains fixed throughout the training run

Impact

Model’s actual behavior and output

Training efficiency, convergence speed, final model quality

Tuning method

Learned through gradient descent or similar algorithms

By hand; can be tuned via techniques such as Bayesian optimization

Summary

AI is based on a complex network of learning methods, model structures, and data strategies. This chapter explores how machines actually learn from mapping inputs to known outcomes in supervised learning, discovering hidden patterns through unsupervised methods, and refining behavior via feedback in reinforcement learning. These three learning families are essential to understanding what kind of intelligence a model is aiming to build.

This chapter also examines how a model works by looking at what a model really is: not just a code block or an equation but a structured representation of relationships that learns through training. Parameters that are tuned to minimize prediction error define what the model learns; hyperparameters, in contrast, define how the model learns. We have explored how training data is split, how loss is measured, and how models are evaluated for generalization.

Understanding this machinery is essential as we start to explore the algorithms behind the general processes. In the next chapter, you will see how the underlying algorithms of AI operate, when to use them, and how to judge their performance in real-world applications.

800 East 96th Street, Indianapolis, Indiana 46240