Concepts / Optimization and Model Training

Optimization and Model Training

In plain words, probability theory is the part of the toolkit that lets a model talk about uncertainty, both in the data it learns from and in the predictions it makes.

  • Programming

Asking What Lies Beneath the Algorithms

Many introductions to machine learning show you what a method does and how it behaves, and they leave the underlying mathematics for later. That is a sensible order. It lets a newcomer build intuition about common algorithms before facing every equation. This article picks up where those introductions tend to stop and asks a simple question: if the algorithms can be understood intuitively, what mathematics sits underneath them?

The short answer is that many of these models rely on principles from three areas: probability theory, linear algebra, and optimization. You do not need to master every implementation detail of these algorithms to use them, but knowing some of the theory behind them is valuable. Before reading on, make a guess about the first of these areas.

What do you think happens?

Which of the three areas is concerned with describing uncertainty in data and in predictions?

  • Probability theory

  • Linear algebra

  • Optimization

Reveal answer
Answer:

Probability theory

Probability theory helps describe the uncertainty that appears in data and in model predictions. Linear algebra organizes data as collections of numbers, and optimization searches for better model settings.

Three Roles Inside One Model

A useful way to picture a machine learning model is as a machine built from several parts. Some parts describe how uncertain or noisy the data is. Some parts organize the data into a structured form so that it can be manipulated. And some parts decide how the model should change to become better at its task. Each of the three labels names a body of mathematics that supplies tools for one of these roles.

The diagram below shows the relationship. Each of the three foundations supplies principles to the same family of models, so a single model can draw on more than one of them at once. The diagram is a simplification. It does not claim that every model uses every foundation equally, and it does not claim these three areas are the only mathematics involved. It only reflects the fact that many models use principles from all three.

Probability theorydescribes uncertaintyLinear algebraorganizes data as numbersMany machine learningmodelsdraw on principles from allthreeOptimizationsearches for bettersettingssupplies principlessupplies principlessupplies principles
How do the three mathematical areas relate to one another and to the models they underpin?

Probability: Describing Uncertainty

Probability theory is the first foundation. Many machine learning models use its principles. Probability gives a language for situations where the outcome is not fully known in advance. Data collected from the world almost always contains variation, and a model that makes predictions from such data has to deal with that variation somehow. Probability theory is one of the main mathematical tools for reasoning about that uncertainty.

Key point

In plain words, probability theory is the part of the toolkit that lets a model talk about uncertainty, both in the data it learns from and in the predictions it makes.

Linear Algebra: Organizing Data as Numbers

Linear algebra is the second foundation. It is concerned with collections of numbers arranged in ordered structures, and with the operations that can be performed on those structures. In machine learning, a dataset is often arranged in exactly this kind of ordered form: each example is one row of numbers, and each measured feature is one column. Linear algebra supplies the rules for working with such arrangements efficiently.

Part of the datasetHow it is arrangedWhat it represents
Each exampleOne row of numbersOne record being learned from
Each measured featureOne columnOne measured property across all records
The whole datasetAn ordered arrangement of rows and columnsThe structure that linear algebra operates on

How a dataset is organized so that linear algebra can work with it

The value of this view is that a whole table of numbers can be handled as one object. Instead of processing each number separately, the rules of linear algebra let you describe and manipulate the entire arrangement at once.

Optimization: Picking the Best Candidate

Optimization is the third foundation. In broad terms, it is about finding the best option from a set of possibilities according to some measure of quality. You start with several candidates, you score each one with the quality measure, and you keep the one with the best score. The measure decides what counts as best, so choosing it is part of the problem.

Candidate Aone set of settingsCandidate Bone set of settingsQuality measurescores each candidateBest option kepthighest quality scoreCandidate Cone set of settingsscoredscoredscoredselects
How do candidate settings get compared by a quality score, so that the one with the best score is kept as the answer?

Learning in a machine learning model can be seen as a search of exactly this kind. The model's settings are adjusted so that its behavior on the training data becomes better by the chosen measure. The candidates in the diagram are simply different settings, and the quality measure is the yardstick used to compare them.

Training as Repeated Adjustment

Training is not a single calculation. It is a loop. Begin with the model's current settings, measure how it behaves on the training data, compare that behavior to the chosen quality measure, and adjust the settings. Then measure again. The diagram traces one pass through this loop and the return to the start.

Current settingsthe model as it standsMeasure on trainingdatabehavior on the examplesCompare to qualitymeasureis it better?Adjust settingschange the settingsmeasurescorepropose changenext round
What happens to the model's settings and its measured quality on the training data across repeated adjustment steps?

The following trace is an invented teaching example, not a description of any particular algorithm. It has one setting, called w, and a quality score measured on the training data, where higher is better. Each round proposes a small nudge upward and keeps the nudge only if the score improves.

Worked example

Tracing Settings and Quality Across Rounds

A model has one setting w that starts at 1.0. Each round tries w plus 0.5. The quality score on the training data is higher when better. Trace the settings and scores for three rounds, and decide what the search keeps.

  1. 1
    Round 0, starting point

    The setting is w = 1.0 and the measured quality score is 4. This is the current model.

  2. 2
    Round 1, first nudge

    Trying w = 1.5 gives a score of 6. The score improved, so the new setting is kept.

  3. 3
    Round 2, second nudge

    Trying w = 2.0 gives a score of 7. The score improved again, so 2.0 is kept.

  4. 4
    Round 3, third nudge

    Trying w = 2.5 gives a score of 6. The score got worse, so 2.5 is rejected and the setting stays at 2.0.

Result

The search keeps w = 2.0, the candidate with the best quality score it found. This toy rule is only for illustration. Real training procedures are not described in this topic, and the rule here is not a claim about how any real model is trained.

Mistakes Learners Make With These Foundations

  • Common mistake

    Believing you must master every equation before you can use a model

    Why it fails

    The topic states that a practitioner does not need to master every implementation detail of these algorithms, although knowing some of the theory is valuable.

    Do this instead

    Build intuition first, then study the theory in steps as your needs grow.

  • Common mistake

    Thinking training is a one-time calculation

    Why it fails

    Training is described as an adjustment process in which settings change so that behavior on the training data improves by the chosen measure.

    Do this instead

    Picture training as a loop of measuring, comparing, and adjusting, as shown in the training loop diagram.

  • Common mistake

    Assuming one foundation is the only one a model uses

    Why it fails

    Each of the three foundations supplies principles to the same family of models, and a single model can draw on more than one at once.

    Do this instead

    Ask which foundation supports each part of a model rather than assigning the whole model to one area.

  • Common mistake

    Treating the quality score as an absolute judgment of the model

    Why it fails

    Improvement is defined relative to the chosen quality measure, so the score is only as meaningful as that measure.

    Do this instead

    Before trusting a score, ask what the measure rewards and whether it matches the goal.

Why Theory Pays Off and Where to Go Next

Understanding the theory behind an algorithm helps a practitioner reason about why it behaves as it does, even when the implementation is handled by existing tools. Knowing that probability describes uncertainty, that linear algebra organizes data as ordered numbers, and that optimization searches for better settings gives you three questions to ask about any model you meet.

The source recommends books for readers who want to go further than an introductory treatment. It suggests reading at least one of them and digging deeper. The recommended books are not named in the material available for this article, so look for the books on probability, linear algebra, and optimization that suit your level.

Practice Reasoning About the Three Areas

EASY

A friend says, 'Training a model means finding the one correct answer in one step.' Using what you learned about optimization and training loops, explain what is wrong with this statement and describe what training does instead.

Hints
  • Recall that training is described as adjusting settings in a repeated loop.
  • Think about what the quality measure is used for when comparing candidates.

Key Takeaways

  • Many machine learning models rely on principles from three mathematical areas: probability theory, linear algebra, and optimization.
  • Probability theory describes uncertainty in data and predictions, linear algebra organizes data as ordered rows and columns of numbers, and optimization searches for better model settings.
  • Optimization means finding the best option from a set of possibilities according to a quality measure, and training is a search of this kind that adjusts settings to improve behavior on training data by that measure.
  • A practitioner does not need to master every implementation detail, but understanding the underlying theory is valuable, and recommended books offer a route to deeper study.

Related concepts

More concepts starting with O