🔷 WEEK 1 Lesson 2
Title: Math for Machine Learning — Vectors & Matrices (Linear Algebra Intuition)
Lesson Objective.
By the end of this lesson, learners will:
Understand why linear algebra is foundational in ML
Understand what vectors represent in real datasets
Understand datasets as matrices
Build intuition for matrix multiplication
Understand how models compute predictions mathematically
No probability.
No distributions.
Only linear algebra intuition for engineers.
1. Why Math Matters in AI Engineering
Machine Learning models are not magic.
They are mathematical functions.
When you train a model, you are:
Adjusting numerical weights
Multiplying inputs
Combining values
Producing outputs
If you don’t understand the math behind it, you cannot:
Debug model behavior
Interpret outputs
Understand scaling issues
Optimize systems
AI Engineers do not memorize formulas.
They understand structure.
Linear algebra is the structure.
2. What Is a Vector? (Engineering View)
A vector is simply:
An ordered list of numbers.
In ML, a vector represents features of one data point.
Example:
A student performance record:
[Hours Studied, Attendance %, Assignment Score]
That list is a vector.
Another example:
A house:
[Size, Bedrooms, Location Score, Age]
Every row in your dataset is a vector.
In machine learning:
Input = feature vector
Output = prediction
Vectors are how models “see” the world.
3. Features as Vectors
Every problem must be converted into numbers.
Images → pixel values
Text → embeddings (numerical representations)
Audio → frequency values
Financial data → numeric indicators
No matter the domain:
Everything becomes a vector.
This is the first mindset shift:
AI systems do not understand meaning. They understand numbers arranged in vectors.
4. What Is a Matrix?
A matrix is a collection of vectors arranged in rows.
If one vector represents one data example,
Then a matrix represents the entire dataset.
Structure:
Rows → Examples
Columns → Features
Example dataset:
| Size | Bedrooms | Location | Age |
|------|----------|----------|-----|
| 1200 | 3 | 8 | 10 |
| 900 | 2 | 6 | 15 |
This table is a matrix.
In Python (conceptually), your dataset becomes:
X = matrix of shape (number_of_examples, number_of_features)
Understanding this structure is critical.
Dataset Matrix X (3 examples, 4 features):
| 1200 | 3 | 8 | 10 | ← House 1 vector
[ 900 2 6 15] ← House 2
[1500 4 9 5] ← House 3
5. Model Weights as Vectors
A simple ML model works like this:
Prediction = Input × Weights
If input is:
[Size, Bedrooms, Location, Age]
Then the model also has:
[Weight₁, Weight₂, Weight₃, Weight₄]
The model multiplies each feature by its weight, then adds them together.
That operation is linear algebra.
6. Matrix Multiplication Intuition
When we scale this to thousands of examples:
Instead of:
One vector × one weight vector
We do:
Dataset matrix × weight vector
This produces:
A vector of predictions.
Matrix multiplication allows models to compute:
Many predictions at once.
This is how neural networks operate internally.
Layer by layer:
Input matrix × weight matrix → output matrix.
Everything is structured multiplication.
7. How Models Compute Predictions
Let’s simplify it.
Step 1: Convert real-world problem into numeric features.
Step 2: Organize features into a matrix.
Step 3: Initialize weights.
Step 4: Multiply input matrix by weight matrix.
Step 5: Produce predictions.
That’s it.
Even deep neural networks are repeated matrix multiplications with transformations.
Linear algebra powers:
Linear regression
Logistic regression
Neural networks
Transformers
Computer vision systems
Everything starts here.
Mini Practical Exercise
Create a small dataset with:
5 rows
3 features per row
Represent:
Each row as a vector
The full dataset as a matrix
Imagine a weight vector of 3 numbers.
Manually compute:
One prediction (dot product).
Write your explanation of what happened mathematically.
Explain in 2–3 sentences what happens if one feature (e.g., 'Location Score') has much larger numbers than others—why scaling matters before multiplication.
Week 1 – Lesson 2 Outcome
Students now:
✔ Understand vectors as feature containers
✔ Understand datasets as matrices
✔ Understand matrix multiplication intuition
✔ Understand how models compute predictions
✔ Think structurally about ML systems
Next:
🔷 Week 1 – Lesson 3
Math for ML — Probability, Distributions & Debugging Intuition
And here, we introduce uncertainty properly—why predictions aren't certain, and how that affects debugging in real African datasets (e.g., noisy crop yields)."
Powered by Soft AI Africa | Training the Next Generation of AI Leaders in Africa.