Machine learning models · Phase 1 · Lesson 6

The maths needed for machine learning

Recognise the roles of vectors, matrices, derivatives, probability and logarithms in model training.

This is one focused step in the 60-lesson course. Use the retrieval check before moving on.

Lesson goal

Recognise the roles of vectors, matrices, derivatives, probability and logarithms in model training.

The core idea

Most machine-learning maths is bookkeeping for three operations: represent data, measure error and adjust parameters.

Mental model

Picture it this way. Most machine-learning maths is bookkeeping for three operations: represent data, measure error and adjust parameters. The important question is what assumption this picture makes, and whether that assumption fits the data.

Mathematical core

Vectors store features, matrices store batches, a derivative gives a local slope, and a gradient points towards the direction of fastest increase. Optimisation usually moves against that gradient.

Worked example

A linear model computes a dot product between a feature vector and weight vector, adds a bias, evaluates a loss and updates the weights.

When to use it

It earns a place when

  • Use the maths to predict how a change in an input or parameter should affect the output.
  • You can evaluate it against a credible baseline.
  • Its output fits the decision and data constraints.

Do not make it the default when

  • Do not postpone all intuition until you can do advanced proofs. The early goal is to follow the computation and its assumptions.
  • A simpler model has not been tested.
  • The data or target definition is still unclear.

Failure modes

Watch for this. Shape errors, unit mismatches and unstable scales cause practical failures even when the equations are correct.

When a result looks surprisingly good, inspect the split, target timing, error slices and data-generating process before celebrating.

Python practice

Use this as a small experiment rather than a recipe to copy blindly. Change one thing, record the result and explain the change.

Use NumPy to create a 2 by 3 matrix, multiply it by a length-three weight vector, and inspect the output shape.

Retrieval check

Answer from memory first. The buttons reveal feedback, but the durable step is explaining why.

1. What does a vector often represent?

2. What does a gradient describe?

3. Why are logarithms common in probability losses?

Transfer prompt. Describe one real problem where this model or idea would be a sensible candidate. Name the target, the main risk and the metric you would inspect.

Primary source

An Introduction to Statistical Learning. Use the source for the deeper treatment after you can explain the lesson's core idea without looking.