Week 1 · What is machine learning, and which maths do we need?
Read the words of the video
- Imagine teaching a young cousin to tell mangoes from bananas. Instead of long rules about shape and color, you just show them many fruits, saying "mango" or "banana" each time. Soon, they learn to identify new fruits on their own! This is just like machine learning.
- Computers can't see mangoes directly. They only understand numbers! So, our first big step in machine learning is to turn everything, like a house or a photo, into lists of numbers. These lists are called vectors. Once we have numbers, mathematics can help the computer find hidden rules to learn from.
- Let's find the length of a vector like (3, 4). Imagine three steps right, then four steps up. The straight line distance from start to end is the length. Using Pythagoras' theorem, square three and four, add them, then take the square root. That gives us five. Easy!
- For your exams, remember the key words like 'loss functions' and 'classification.' Pay attention to details like 'norm' meaning length, not squared length. And know that 'squared loss' is for numbers, while 'zero-one loss' is for categories. Keep practicing turning the world into numbers. You've got this!
The one-minute story
Imagine you want to teach a little cousin to tell mangoes from bananas. You could write rules: "if it is long and yellow, it is a banana". Soon you hit trouble: green bananas, short mangoes, half-ripe everything.
Or you could do what really works: show your cousin lots of fruit, and say the name each time. After enough examples they just get it, even for fruit they have never seen.
That is machine learning. Instead of writing the rules, we show a computer lots of examples and let it find the rules.
The catch: a computer cannot look at a mango. It only understands numbers. So the first job in this whole course is: turn the world into numbers, and then do clever things with those numbers. That is exactly why we study maths here.
By the end of this week you will be able to:
- say what a data point, a feature, a label and a model are;
- tell regression, classification, clustering and dimensionality reduction apart;
- turn a data point into a vector and measure its length, the distance between two of them, and how much they point the same way (the dot product);
- measure how wrong a model is with a loss function.
Words you need
- Data point - one example. One house, one student, one photo.
- Feature - one measurable fact about a data point. For a house: area, number of bedrooms, age.
- Label (or target) - the answer we want to predict for that data point. For a house: its price. For a photo: "cat" or "dog".
- Dataset - the whole pile of data points (and labels, if we have them).
- Model - a rule, written as a formula, that takes features in and gives a prediction out.
- Training - showing the model the examples so it can adjust itself.
- Prediction - what the model says for a new data point.
- Loss - a number that says how wrong the model is. Smaller is better.
Idea 1: Everything becomes a list of numbers (a vector)
A house for sale is described on a board outside: 120 square metres, 3 bedrooms, 10 years old. Write that as a list: .
That list of three numbers is a vector. You can picture it two ways, and both are useful:
- as a point in space (go 120 along one road, 3 along another, 10 along a third), or
- as an arrow from the starting corner to that point.
A vector with numbers lives in -dimensional space, written . Do not panic about 1000 dimensions. We only ever draw two, and every rule we learn on the page works unchanged in 1000.
A photo of pixels is just a vector of brightness numbers. A sentence can become a vector of word counts. Once your data is vectors, maths can touch it.
The length of a vector (its norm)
Pythagoras gives the length of an arrow. For :
In dimensions you just keep adding squares under the root: . This is called the norm (or length, or Euclidean norm).
The distance between two points
The distance between and is the length of the arrow from one to the other:
Later, k-means (MLT week 3) will group points by this distance, and k-NN (MLT week 7) will predict from the nearest neighbours. Same formula.
The dot product: do two arrows point the same way?
Multiply matching entries and add:
Two people pushing a heavy box. If they push in the same direction, the pushes add up: big positive dot product. If they push at right angles, the second person does nothing useful for the first: dot product zero. If they push against each other: negative.
The dot product hides an angle inside it:
So perpendicular vectors have dot product 0 (because ). You will use that sentence all course long. And since is never bigger than 1, we always have (the Cauchy-Schwarz inequality), with equality only when the arrows are parallel.
A unit vector has length 1. To make one from any vector, divide by its own length: . It keeps the direction and throws away the size.
Idea 2: The four big families of learning
| Family | What you give the computer | What it must produce | Everyday picture |
|---|---|---|---|
| Regression (supervised) | examples with a number as the answer | a prediction that is a number | "Guess this house's price" |
| Classification (supervised) | examples with a category as the answer | a category | "Is this email spam or not?" |
| Clustering (unsupervised) | examples with no answers | groups of similar things | "Sort these photos into piles" |
| Dimensionality reduction (unsupervised) | examples with no answers | the same data using fewer numbers | "Describe a face with 5 numbers instead of 10,000" |
Supervised means a teacher gave you the right answers (labels). Unsupervised means no teacher; the computer finds structure by itself.
The classic confusion: is the answer a number you can add and average, or a name?
- Predicting tomorrow's temperature in degrees: regression (24.3 and 24.4 are close, and "close" matters).
- Predicting whether it will rain: classification (rain / no rain are just names).
- A rating of 1 to 5 stars is the tricky one: if the order and gaps matter we treat it as regression; if each star level is just a bucket we treat it as classification. Read what the question says.
Idea 3: Learning means making the loss small
A teacher marks your homework. She does not just say "wrong". She says how wrong: off by 1 mark, off by 20 marks. A loss function is that marking rule for a model. Training is the model repeatedly looking at its marks and adjusting to lose fewer of them.
Say the true values are and the model predicts (read "y-hat").
Squared loss (used for regression). Square each error so that over- and under-shooting both count, and big mistakes count extra:
0-1 loss (used for classification). A mistake costs 1, a correct answer costs 0:
Averaged over the data, the 0-1 loss is simply the fraction of mistakes.
Reconstruction loss (used in dimensionality reduction). We squash a data point into fewer numbers, then try to rebuild it, and measure how far the rebuilt point is from the original: . You will meet this again in PCA (MLF week 6, MLT week 1).
Train error, test error, and memorising
Suppose a student memorises last year's question paper word for word. Give them last year's paper: 100%. Give them a fresh paper: disaster. They memorised instead of learning.
A model can do the same. So we keep some data hidden: train on one part, test on the part the model has never seen. The test score is the honest one. A model that is great on training data and poor on test data has overfit.
Solved examples
Question. Let and . Find , the distance between and , and the unit vector in the direction of .
Solution.
- Length of : .
- Difference: . Its length is . So the distance is 5.
- Unit vector: divide by its length: . Check: .
Notice : points the same way but is twice as long, so and the distance between the tips is .
Question. and . Find and the angle between them.
Solution.
- .
- and .
- .
- .
Positive dot product, small angle: the arrows lean the same way. Now try : , so . They are at exactly .
Question. Name the type of problem.
(a) Given a person's age, income and city, predict how many rupees they will spend next month. (b) Given a bank customer's record, decide "will repay" or "will default". (c) Given 10,000 shoppers' purchases with no other information, find groups of similar shoppers. (d) Given photos described by 4,096 numbers each, find 20 numbers that capture most of the information.
Solution. (a) regression: the answer is an amount of money. (b) classification: two named outcomes. (c) clustering: no answers given, we want groups. (d) dimensionality reduction: the same photos in fewer numbers. (a) and (b) are supervised; (c) and (d) are unsupervised.
Question. A regression model predicts for true values . Find the MSE. Then a classifier predicts (cat, cat, dog, dog) for true labels (cat, dog, dog, cat). Find its 0-1 loss.
Solution.
- Errors . Squares: . Sum . MSE .
- Compare label by label: cat=cat right, dog vs cat wrong, dog=dog right, cat vs dog wrong. Two mistakes out of four, so 0-1 loss .
The one big miss (error ) cost 4 in squared loss, four times what the error of 1 cost. That is what "big mistakes count extra" means.
Your turn
Is perpendicular to ?
Show the full solution
Perpendicular means dot product zero. . Yes, they are perpendicular.
Two houses are and (area, bedrooms, age). How far apart are they?
Need a hint?
The first thing to try: subtract the vectors.
Show the full solution
. Squares: , sum , so the distance is .
(In real life you would first rescale the features. Area is measured in the hundreds and age in single digits, so area would dominate the distance. That idea comes back in MLP.)
and . What is the largest value can take, and when does it happen?
Need a hint?
Use and think about how big can be.
Show the full solution
, so . It happens when , i.e. the vectors are parallel (same or exactly opposite direction). This exact question, "max of given the two lengths", appears in real papers.
A model predicts the price of a taxi ride. Another model predicts whether a passenger will give a tip. Which loss suits each, and why?
Need a hint?
Ask first: is each answer a number or a category?
Show the full solution
The price is a number, so use squared loss (MSE): being off by Rs 50 is worse than off by Rs 5, and squaring reflects that. The tip decision is yes/no, a category, so use 0-1 loss: it just counts the mistakes.
Exam radar
From the 53 MLF Quiz 1 papers on the practice site, the summaries mention these week-1 ideas most often: loss functions (21 papers), dimensionality reduction (20), clustering (20), supervised learning (16), regression (15), classification (15), classification vs regression (13), mean squared loss (8), reconstruction loss (6).
The questions are mostly short, conceptual and worth 2 to 3 marks. They reward knowing the vocabulary exactly, so make sure you can say each of those words in your own sentence.
- A norm is a length, not a squared length. is the squared norm. If the question asks for the distance and you give the squared distance, the option you pick will be the planted wrong one.
- Squared loss is for numbers; 0-1 loss is for categories. Do not mix them up.
- Zero dot product means perpendicular only for non-zero vectors; the zero vector has dot product 0 with everything.
- "Unsupervised" does not mean "no maths": it means no labels.
Quick quiz
Predicting whether a customer will cancel a subscription (yes/no) is...
- regression
- classification
- clustering
- dimensionality reduction
Which of these is a unit vector?
- (1, 1)
- (0.6, 0.8)
- (3, 4)
- (0.5, 0.5)
Two non-zero vectors have dot product 0. What is the angle between them?
- 0 degrees
- 45 degrees
- 90 degrees
- 180 degrees
Which of these are TRUE about squared loss and 0-1 loss? (select all that apply)
- Squared loss punishes big errors much more than small ones.
- 0-1 loss over a dataset equals the fraction of wrong predictions.
- 0-1 loss is the usual choice for predicting house prices.
- Squared loss can be negative.
Recap
- ML = learn the rules from examples instead of writing them. Data must become numbers: each data point is a vector.
- Norm ; distance ; dot product ; perpendicular means .
- Regression = predict a number; classification = predict a category; clustering and dimensionality reduction = no labels.
- A loss function measures how wrong the model is: squared loss (regression), 0-1 loss (classification), reconstruction loss (dimensionality reduction).
- Judge a model on data it has not trained on.
- Norm:
- Distance:
- Dot product: ; perpendicular
- Cauchy-Schwarz:
- Unit vector:
- Squared loss: ; MSE
- 0-1 loss: if , else ; average = fraction of mistakes
- MLT week 1 - PCA: finding the best view of your data: MLT starts by treating every data point as a vector. Vectors, lengths and dot products are MLF week 1.
- MLP week 1 - Your first end-to-end ML project: What 'learning from data' means, then your first end-to-end project.
Practise with real exam questions
These come straight from past papers (with the real figures and the official answer key). Open 16 real questions on this week All Quiz 1 papers