Skip to main content

Math for Machine Learning

Learning Objectives

By the end of this lesson, you will be able to:

  • Explain why math matters in machine learning.
  • Identify the core math ideas used in ML: algebra, vectors, matrices, probability, and basic calculus.
  • Interpret common ML expressions like loss, gradients, and probabilities.
  • Use a simple mathematical lens to understand ML models in later lessons.

Introduction

Machine learning is not magic. It is mathematics applied to data and optimization.
If you understand the math underneath, you can read model behavior more clearly, debug more effectively, and make better design decisions.

In the Flow Initiative, this lesson gives you the minimum mathematical foundation needed to move into:

  • supervised learning,
  • neural networks,
  • evaluation metrics, and
  • AI system design.

You do not need to be a mathematician. You need to be comfortable with the language of ML math.

Why Math Matters

Math helps you answer questions like:

  • How does a model represent data?
  • How does it learn from examples?
  • How do we know if it is improving?
  • Why does one model fit better than another?

Without math, machine learning becomes a black box.
With math, it becomes a system you can reason about.

Core Math Concepts

1. Algebra

Algebra is the language of relationships between quantities.

In ML, algebra appears in:

  • linear equations,
  • feature combinations,
  • loss functions,
  • parameter updates.

A simple example is:

y = wx + b

This says the output y is computed from an input x, a weight w, and a bias b.
This simple formula is the basis for many ML models.

2. Vectors

A vector is a list of numbers that represents an object or sample.

For example, a student profile might be represented as:

x = [hours studied, attendance, quiz score]

Vectors let models work with multiple features at once.
They are the basic data structure of many ML systems.

3. Matrices

A matrix is a grid of numbers.
Matrices are used to:

  • store datasets,
  • transform vectors,
  • represent model weights.

If a vector is one sample, a matrix can represent many samples or many transformations at once.

4. Probability

Probability helps ML deal with uncertainty.

You use probability to think about:

  • chance of a class label,
  • confidence in a prediction,
  • noisy data,
  • random sampling.

A common idea is conditional probability:

P(A | B)

which means the probability of A given that B has happened.

5. Statistics

Statistics helps summarize data.

Important ideas include:

  • mean,
  • median,
  • variance,
  • standard deviation.

These help you understand:

  • how spread out your data is,
  • whether your model is stable,
  • and whether one group differs from another.

6. Calculus

Calculus is used in ML mostly for optimization.

The main idea you need is the derivative, which tells you how a function changes when its input changes.

In ML, we use derivatives to answer:

  • Which direction should we change the model?
  • How much should we update the weights?
  • Is the loss going up or down?

This is the foundation of gradient descent, which you will meet in later lessons.

Math in the ML Workflow

A typical ML workflow uses math at every step:

  1. Represent data with vectors and matrices.
  2. Compute predictions using formulas.
  3. Measure error with a loss function.
  4. Update parameters using gradients.
  5. Repeat until the model improves.

This is why math is not separate from ML — it is ML.

Key Terms

Feature

A measurable property of data, such as age, price, temperature, or clicks.

Label

The correct answer the model is supposed to predict.

Weight

A number that controls how much a feature influences the output.

Bias

A constant value added to shift the output.

Loss

A number that measures how wrong a model is.

Gradient

A direction and rate of change used to improve model parameters.

Epoch

One full pass through the training data.

Why This Matters for Flow Engineers

If you work on AI/ML systems in the Flow Initiative, this math foundation helps you:

  • understand model behavior,
  • reason about training and evaluation,
  • compare algorithmic choices,
  • and explain ML outputs clearly to non-specialists.

This is especially useful in African-centric contexts where systems need to be:

  • efficient,
  • interpretable,
  • and robust under real-world constraints.

Practical Exercises

Exercise 1: Represent a Simple Dataset

Write down three student records with features like:

  • hours studied,
  • attendance,
  • quiz score.

Then write each student as a vector:

x1 = [h1, a1, q1]
x2 = [h2, a2, q2]
x3 = [h3, a3, q3]

Exercise 2: Interpret a Formula

Given:

y = 2x + 3

Answer these questions:

  • What is x?
  • What does the 2 mean?
  • What does the 3 mean?
  • How does y change when x increases?

Exercise 3: Think About Error

Imagine a model predicts exam scores.
If the model predicts 70 and the actual score is 85:

  • What is the error?
  • Is the model too low or too high?
  • How could you reduce the error?

Self-Assessment

Rate yourself from 1 to 5:

  • I understand why math is important in ML.
  • I can explain vectors and matrices in simple terms.
  • I know what a loss function is.
  • I understand why derivatives matter for optimization.

Action item: write a short note in your lab repo explaining one ML concept using a math formula (keep it in inline style like y = wx + b).

Next Steps

  • Read 02-linear-algebra-for-ml.md next to go deeper into vectors and matrices.
  • Use this lesson as a reference when you encounter ML formulas later.
  • Treat math as the operating language of machine learning.

This lesson gives Flow Initiative trainees a practical mathematical foundation for machine learning, focusing on algebra, vectors, matrices, probability, statistics, and calculus as the core tools for understanding ML systems.