Lesson 1 · Introduction
⏱ 37 min read
The main goal of the lecture
Not to memorise dozens of definitions, but to understand what actually happens in machine learning — from the real world and data all the way to a trained model and its use on new data.
We will keep coming back to one example: we want to teach a computer to predict the price of an apartment. That way we do not study the terms one by one, but see how they join into a single process.
The single most important picture in the whole lecture
↻ The error travels back: the model uses it to change its parameters, and the cycle repeats. That closed loop is what training is.
The whole lecture is really an explanation of this diagram. For example:
We have real apartments → we collected information about them → we wrote down their characteristics and prices → we got a dataset → we chose an ML task → the model makes predictions → we measure the errors → during training we change the model's parameters → we get a trained model → we check whether it can work on new data → after that we use it for new apartments.
That is exactly the story we need to learn to tell in our own words right now.
1. What machine learning is
1.1. First, in the simplest possible words
Machine Learning (ML) is a way of building programs that do not receive every rule of behaviour ready-made from a programmer, but instead find useful patterns in the data.
For example, we want to determine:
Is this email spam?
We could write an ordinary program:
if the email contains "earn money"
and has many links
and the sender is unknown
→ it might be spam
But the problem is that human language is far too complex. Spam can look completely different:
"Congratulations! A special bonus is available to you..."
And tomorrow a new kind of spam will appear that the programmer never anticipated. In ML we can take a different route.
We show the computer many examples:
| Correct answer | |
|---|---|
| "You've won a million!" | spam |
| "Meeting tomorrow at 15:00" | not spam |
| "Get your gift right now!" | spam |
| "Here are the project documents" | not spam |
And we say:
Here are the examples. Find the patterns that let you tell spam from normal email.
The model analyses the examples and tunes its internal parameters so that it reproduces the correct answers well.
1.2. Why is it called "learning"?
Here the word learning does not mean that the computer learns the way a human does. The computer does not sit and reflect:
"Aha, now I see what the essence of spam is."
It performs mathematical computations.
We call the process learning because the model receives examples and changes its internal parameters on the basis of those examples in order to do the task better.
That is:
flowchart TD
A1["data"] --> A2["prediction"] --> A3["compare with the correct answer"] --> A4["error"] --> A5["parameter update"] --> A6["new prediction"]
Gradually the model's parameters become such that it solves the given task better and better.
2. ML and ordinary programming
This is one of the most important ideas.
Ordinary programming
In classical programming a human writes the rules:
flowchart TD
N1["rules + data"] --> N2["program"] --> N3["result"]
For example:
if temperature > 38
→ print "high temperature"
The programmer defined the rule in advance.
Machine learning
In ML we often want to obtain the rules themselves from examples:
flowchart TD
N1["data + correct answers"] --> N2["training"] --> N3["model"]
And then:
model + new data
↓
prediction
That is:
Classical programming
flowchart TD
N1["RULES + DATA"] --> N2["RESULT"]
Machine learning
flowchart LR
A["data + answers"] --> B["model"]
flowchart TD
C["model + new data"] --> D["prediction"]
That is the fundamental difference.
3. What exactly does a model learn?
This is where an important thought appears:
A model does not learn the whole real world.
It gets a certain view of the world through data. Let us imagine apartments.
In the real world an apartment has a huge number of properties:
- floor area;
- rooms;
- floor;
- neighbourhood;
- condition of the renovation;
- view from the window;
- noise;
- distance to the metro;
- condition of the building;
- whether there is a balcony;
- and hundreds of other things.
But we can give the model only part of that information:
floor area
number of rooms
floor
distance to the centre
The model will look for a relationship between this data and the price.
3.1. What is a pattern?
A pattern (a regularity) is a stable relationship between certain quantities or properties. For example:
On average, more spacious apartments cost more.
That is a pattern. But it is not an absolute rule.
A 100 m² apartment on the outskirts can cost less than a 60 m² apartment in the centre. That is why ML usually looks not for a simple rule:
"if the area is larger → the price is always higher."
but for a more complex dependence:
"the price is related to the area, the number of rooms, the location and other features in a certain way."
3.2. Dependence
A dependence is a situation where a change in one property is connected with a change in another. For example:
area ↑
↓
price on average ↑
The model tries to detect such dependences in the data.
3.3. Pattern
A pattern is a recurring regularity or structure. For example, if the model sees many times that:
flowchart LR
A["apartments<br/>near the metro"] --> D["usually<br/>a high price"]
B["a good<br/>neighbourhood"] --> D
C["a large<br/>floor area"] --> D
it can detect the corresponding pattern.
3.4. Prediction
Prediction is the result the model produces for the input data.
For example:
flowchart TD
A["area 80 m², rooms 3,<br/>floor 5"] --> B["MODEL"] --> C["ŷ = 12,000,000 ₽"]
The model does not "know the future". It uses the patterns it found in the data to obtain the most suitable result.
4. Object
Now we need to learn to speak about data correctly.
In simple words
An object (sample / instance / observation) is one specific example that the model works with. For example:
- one apartment;
- one customer;
- one photograph;
- one patient;
- one email.
That is:
an object is one unit of data.
An apartment, for example
Suppose we have:
Apartment #1
That is one object. And also:
Apartment #2
That is the second object. And so on.
Why is an object usually a row of a table?
Because a table is convenient to organise like this:
| Apartment | Area | Rooms | Floor | Price |
|---|---|---|---|---|
| #1 | 50 | 2 | 3 | 8M |
| #2 | 80 | 3 | 5 | 12M |
| #3 | 45 | 1 | 2 | 7M |
Each row is a separate apartment. That is:
flowchart LR
A["row 1"] --> B["object 1"]
flowchart LR
C["row 2"] --> D["object 2"]
flowchart LR
E["row 3"] --> F["object 3"]
This is a very useful habit:
Rows usually correspond to objects.
5. Features
Now let us look at what the description of an object consists of.
In simple words
A feature is a characteristic of an object that we use as input information for the model. For an apartment the features could be:
- floor area;
- number of rooms;
- floor;
- distance to the centre.
For example:
Apartment #1 area = 50 m²
rooms = 2
floor = 3
distance to the centre = 5 km
These numbers are the features.
An object and its features are not the same thing
It is important not to confuse them.
Object:
one specific apartment.
Features:
the characteristics of that apartment.
You can picture it like this:
flowchart TD
A["OBJECT<br/>apartment #1"] --> B["area"]
A --> C["rooms"]
A --> D["floor"]
That is:
An object is what we describe.
Features are what we describe it with.
6. Target — the target variable
Now another crucial term appears.
In simple words
Target is what we want to predict.
In our case:
flowchart TD
A["features: area, rooms, floor, distance"] --> B["MODEL"] --> C["price"]
The price is the target.
Formally
If:
- X — the features;
- y — the correct target,
then we want to teach the model to produce a prediction:
flowchart TD
N1["X"] --> N2["model"] --> N3["ŷ"]
Where:
X— the input features;y— the true correct answer;ŷ— the model's prediction.
A very important trio
It is important to remember:
X = what we give the model
y = the correct answer
ŷ = what the model predicted
For example:
X:
area = 80
rooms = 3
floor = 5 y:
12,000,000 ₽ ŷ:
11,500,000 ₽
The model received X, produced ŷ, and the true answer is y.
7. Dataset
In simple words
A dataset is a collection of objects gathered to solve a particular task. For example:
| Object | Area | Rooms | Floor | Price |
|---|---|---|---|---|
| 1 | 50 | 2 | 3 | 8M |
| 2 | 80 | 3 | 5 | 12M |
| 3 | 45 | 1 | 2 | 7M |
| 4 | 100 | 4 | 7 | 18M |
| 5 | 60 | 2 | 4 | 9M |
This is our dataset.
Row
One row usually describes one object:
flowchart LR
N1["row"] --> N2["one object"]
Column
A column contains one property for many objects:
column "Area"
→ the areas of all the apartments
8. Feature matrix
Here the word matrix appears for the first time. There is no need to be scared of it yet.
In this context it is enough to understand:
A feature matrix is a table containing the features of objects.
For example:
| Area | Rooms | Floor | |
|---|---|---|---|
| apartment 1 | 50 | 2 | 3 |
| apartment 2 | 80 | 3 | 5 |
| apartment 3 | 45 | 1 | 2 |
These are our features. We usually denote this table with the letter:
X
Target vector
A vector here can be understood simply as a list of numbers. For example:
y =
[8M,
12M,
7M]
That is:
flowchart LR
A["X"] --> B["features"]
flowchart LR
C["y"] --> D["correct answers"]
There is no need to dive into linear algebra right now. What matters is the structure:
X y features target
───────────── ───────
50 2 3 8M
80 3 5 12M
45 1 2 7M
9. Feature space
Now for a slightly unusual but very important idea.
Let us imagine just two features
Suppose an apartment has:
floor area
number of rooms
Each apartment can be represented as a point. For example:
number of rooms
↑
|
• |
|
• |
|
| •
|
+----------------→ floor area
Why a point? Because the position of a point is determined by its coordinates.
For example:
apartment:
area = 60
rooms = 2
can be represented by the point:
(60, 2)
What is feature space?
Feature space is the space in which objects are represented through their features.
If there are two features:
X₁ = floor area
X₂ = rooms
we get a two-dimensional space. If there are three features — a three-dimensional one.
If there are 100 features — the space has 100 dimensions. We cannot draw 100 dimensions properly on paper, but mathematically such a construction is perfectly normal.
This idea will become especially important later, for example when we study metric methods. For now it is enough to remember:
An object can be represented as a point, and its features as the coordinates of that point.
10. Types of machine-learning tasks
Now we need to understand:
What do we actually want from the model?
The main types of tasks are:
- Regression
- Classification
- Clustering
10.1. Regression
Regression is when we want to predict a numeric value. For example:
flowchart TD
N1["apartment characteristics"] --> N2["model"] --> N3["12,000,000 ₽"]
The price is a number. Other examples:
- temperature;
- salary;
- demand;
- fuel consumption;
- delivery time.
10.2. Classification
Classification is when we need to choose a class / category. For example:
flowchart TD
N1["email"] --> N2["model"] --> N3["spam"]
Other examples:
flowchart LR
A["photograph"] --> B["cat / dog"]
flowchart TD
C["transaction"] --> D["fraudulent / normal"]
flowchart TD
E["patient"] --> F["disease / no disease"]
10.3. Clustering
Clustering is the search for groups of similar objects when there are no correct answers in advance.
For example, an online store has information about its customers:
purchase frequency
average order value
product categories
We do not tell the model:
"Here is group #1, here is group #2, here is group #3."
We ask it:
Find natural groups of similar customers.
The model may detect:
flowchart TD
A["Group A"] --> B["buys often, high order value"]
flowchart TD
C["Group B"] --> D["buys rarely, small order value"]
flowchart TD
E["Group C"] --> F["often buys a particular category"]
Let us compare
| Task | What we get | Example |
|---|---|---|
| Regression | a number | apartment price |
| Classification | a class | spam / not spam |
| Clustering | groups | customer segments |
11. Supervised Learning
Now for the most important split.
The idea
Supervised Learning is learning in which the correct answers are known for the training examples.
Why "supervised"? Because we have something like:
"Here is an example. Here is the correct answer. Learn to produce that answer."
For example:
| Area | Rooms | Price |
|---|---|---|
| 50 | 2 | 8M |
| 80 | 3 | 12M |
| 100 | 4 | 18M |
The model sees:
X + y
That is:
features + correct answers
and learns to establish a relationship between them.
Training examples
A training example is a specific object that is used during training. For example:
area = 80
rooms = 3
price = 12M
The main point
In supervised learning there is:
flowchart LR
A["X"] --> B["features"]
C["y"] --> D["correct answers"]
and the process:
flowchart TD
N1["X + y"] --> N2["training"] --> N3["model"]
Regression and classification are very often supervised-learning tasks.
12. Unsupervised Learning
Here the situation is different. We have:
X
but no correct:
y
That is:
flowchart TD
N1["features"] --> N2["model"] --> N3["discovered structure"]
For example:
flowchart TD
N1["customer data"] --> N2["algorithm"] --> N3["discovered groups"]
We do not say in advance:
"This customer has to end up in group A."
The model tries to detect the structure by itself.
An important difference
Supervised:
X + y → training
Unsupervised:
X → search for structure
Clustering belongs here conceptually.
Unsupervised learning also includes methods for analysing the structure of data, for example PCA (Principal Component Analysis).
But we will not go into the algorithms themselves right now.
13. Semi-supervised Learning
There is an intermediate option as well.
Semi-supervised learning:
part of the data has y
part of the data has no y
For example:
flowchart TD
A["10,000 photographs"] --> B["1,000: labelled"]
A --> C["9,000: unlabelled"]
The labelled data tells the model what the correct answer is. The unlabelled data can also be used to obtain additional information about the structure of the data.
For now it is enough to know the idea itself:
Part of the data is labelled, part of it is not.
14. Reinforcement Learning
This is a different approach altogether. Here there is:
Agent
The one who makes decisions.
Environment
The world in which the agent acts.
Action
What the agent did.
Reward
How good the action turned out to be. For example, a game:
flowchart TD
A1["AGENT"] --> A2["takes an ACTION"] --> A3["ENVIRONMENT"] --> A4["REWARD"] --> A5["the AGENT adjusts its behaviour"]
Suppose an agent is playing a game. It made a move:
flowchart TD
N1["ACTION"] --> N2["move forward"]
And received:
REWARD = +10
Good. Another move:
flowchart TD
N1["ACTION"] --> N2["fell into a trap"]
It received:
REWARD = -10
How does RL differ from supervised learning?
In supervised learning we usually say:
Here is the correct answer.
In reinforcement learning we may not give the correct answer directly. We say:
Act and receive rewards or penalties.
This is a fundamentally different way of learning. But that is enough for now. RL is a big topic in its own right.
15. What is a model?
Now we have come to one of the central concepts.
In simple words
A model is a mathematical or computational construction that takes input data and produces a result — a prediction.
That is:
flowchart TD
N1["X"] --> N2["MODEL"] --> N3["ŷ"]
For example
We give the model:
area = 80
rooms = 3
floor = 5
It returns:
ŷ = 11,700,000 ₽
That is the prediction.
Prediction
Prediction is the result of the model's work for a specific input.
Important:
A prediction is not necessarily "the future".
The model can predict:
- a price;
- a class;
- a probability;
- a score;
- a category.
The word prediction here means:
the result the model computed from the input data.
16. y and ŷ — the true answer and the prediction
We will run into these two notations constantly.
y
This is the true target, the correct value. For example:
y = 12,000,000
ŷ
It is read roughly as:
"y with a hat" or "y-hat".
This is the model's prediction. For example:
ŷ = 11,500,000
We get:
true price:
y = 12M predicted price:
ŷ = 11.5M
The model made a mistake. And here we arrive at the next fundamental concept:
loss.
17. What does "training a model" mean?
Now let us assemble the previous concepts into a single process. Let us imagine we have:
X = apartment features
y = true prices
At first the model may not be tuned very well. It receives:
flowchart TD
N1["X"] --> N2["model"] --> N3["ŷ"]
For example:
y = 12,000,000
ŷ = 8,000,000
Obviously, the prediction is poor. We need to tell the learning algorithm somehow:
"The model is predicting badly. Its internal settings need to change."
And the cycle begins.
Step 1
The model receives data.
Step 2
The model makes a prediction.
flowchart TD
N1["X"] --> N2["model"] --> N3["ŷ"]
Step 3
We compare:
ŷ vs y
Step 4
We get a numerical estimate of the error — the loss.
Step 5
The learning algorithm changes the model's parameters.
Step 6
The model makes a prediction again.
Step 7
We estimate the error again. And so on many times.
flowchart TD
A["data"] --> B["prediction"] --> C["loss"] --> D["parameter update"]
This is what training is called. This is exactly the foundation we need before the next lectures.
18. Parameters
Now a question arises:
What exactly changes during training?
The answer:
A simple analogy
Imagine a device with several knobs:
┌─────────────────┐
│ MODEL │
│ │
│ ○ knob 1 │
│ ○ knob 2 │
│ ○ knob 3 │
└─────────────────┘
The position of these knobs affects the result. During training the algorithm selects their values.
In mathematical models
Parameters are often denoted, for example, as:
w
b
We will see them later in linear regression. What matters now is not how they are computed.
What matters is to understand:
Parameters are the internal quantities of a model whose values the model obtains during training.
That is:
flowchart TD
N1["training"] --> N2["parameter update"] --> N3["change in the model's behaviour"]
19. Parameters vs Hyperparameters
These two concepts are very easy to mix up.
Parameter
This is an internal setting of the model that the learning algorithm selects from the data.
flowchart TD
N1["data"] --> N2["training"] --> N3["parameters"]
Hyperparameter
A hyperparameter is a setting of the training process itself or of the algorithm's structure, which we usually specify before or outside the model's direct selection of parameters.
For example:
- learning rate;
Kin KNN;- the depth of a tree.
The main difference
flowchart TD
A["PARAMETER"] --> B["the model selects it during training"]
flowchart TD
C["HYPERPARAMETER"] --> D["we / the training setup specify it"]
You can picture it like this:
flowchart TD
A1["US"] --> A2["hyperparameters"] --> A3["TRAINING"]
flowchart LR
B1["parameters"] --> B2["MODEL"]
20. Loss
Now we need to answer the question:
How does a model understand that it is doing badly?
Of course, the model itself does not "understand" anything in the human sense. We define a mathematical way to measure the error.
That is the loss function.
The simplest scheme
prediction + target
↓
LOSS
For example:
flowchart LR
A["y = 12M"] --> C["LOSS"]
B["ŷ = 11M"] --> C
The loss tells us:
How badly the model predicted.
Error and loss are not quite the same thing
In everyday speech we might say:
"The model was off by a million."
That is the specific error of a specific prediction.
Loss is a mathematical measure that the algorithm uses to assess the quality of a prediction or of a set of predictions.
For example, for a single object you can get a single loss value. For a large number of objects you can compute the overall loss over the dataset.
Why is it needed at all?
Because we need a goal for training. We want:
LOSS ↓
That is, to find such model parameters that its errors become smaller. We will look at the specific function MSE (Mean Squared Error) in detail in lecture 2.
21. Optimization
Now a very natural chain arises:
flowchart TD
A1["the model predicts"] --> A2["we get the loss"] --> A3["we want to reduce it"] --> A4["the parameters must change"] --> A5["we need good values"]
This is already:
Optimization.
Formally:
We want to find such values of the model's parameters that the loss function becomes as small as possible.
But right now there is no need to memorise optimisation formulas. The main cause-and-effect chain:
flowchart TD
A1["the model makes mistakes"] --> A2["there is a loss"] --> A3["we want to reduce it"]
flowchart TD
B1["we change the parameters"] --> B2["an optimisation problem"]
That is why, after linear regression, we moved on to optimisation in lectures 3–4.
22. Training and inference
This is one of the most important pairs of terms in all of ML. It will be especially useful later when we study LLMs.
Training
During training the model receives data and changes its parameters. The scheme:
flowchart TD
A1["data"] --> A2["model"] --> A3["prediction"] --> A4["loss"]
flowchart TD
B1["update"] --> B2["repetition"] --> B3["trained model"]
Inference
Inference is when training is already over and we take the finished model and give it new data.
For example:
flowchart TD
N1["NEW APARTMENT"] --> N2["trained model"] --> N3["predicted price"]
Here the model no longer has to go through the usual training cycle. It is simply used.
A huge difference
Training
flowchart TD
N1["data"] --> N2["training"] --> N3["model"]
Inference
flowchart TD
N1["new data"] --> N2["trained model"] --> N3["prediction"]
This is especially important to remember. Later, when we talk about LLMs, phrases like:
"the model is training"
and
"the model is doing inference"
will mean exactly these two different modes of operation.
23. Why can we not test a model on the same data?
Suppose we gave the model 1,000 apartments and trained it. After that we ask:
"So, does it work well?"
And we give it the very same 1,000 apartments. We get a very good result.
But the problem is:
the model has already seen this data.
It is like giving a school student 100 questions, making them memorise the answers, and then giving them the same questions and judging how well they understand the subject by their answers.
A high score does not yet prove understanding. That is why the data is usually split.
24. Train / Validation / Test
There are three important sets.
24.1. Training set
These are the data on which the model is directly trained.
TRAIN
↓
the model changes its parameters
24.2. Validation set
Validation is checking the model during development and tuning.
It helps to make decisions:
- which model to choose;
- which hyperparameters to use;
- which version of the model is better.
Very roughly:
flowchart LR
A["TRAIN"] --> B["we learn"]
flowchart TD
C["VALIDATION"] --> D["we choose / tune"]
24.3. Test set
The test set is used for the final evaluation of the model. The main idea:
The test must be as independent as possible from the process of developing the model.
That is, we must not constantly look at the test set and adjust the model to it.
The overall scheme
flowchart LR
A["ALL DATA"] --> B["train: learn"]
A --> C["validation: tune"]
A --> D["test: final check"]
25. Generalization
Here we have come to one of the most important ideas in ML.
What do we actually want?
Not:
"The model works well on the examples we showed it."
But:
"The model works well on new data it has never seen before."
This is called:
Generalization.
An analogy with a student
Let us imagine two students.
Student #1
Memorised:
flowchart LR
A["question 1"] --> B["answer A"]
flowchart LR
C["question 2"] --> D["answer B"]
flowchart LR
E["question 3"] --> F["answer C"]
In the exam they were given the same questions. They scored 100%.
But if a question is changed slightly:
They do not know what to do.
Student #2
Understood the principle. They can solve:
a new problem
they have never seen before.
In ML we want the second option. That is:
flowchart TD
N1["not memorisation"] --> N2["understanding / finding the pattern"] --> N3["working on new data"]
For a model this is called generalization.
26. Overfitting
Now it becomes clear why we need generalization.
Overfitting is a situation where the model has adapted too strongly to the training data and works poorly on new data.
For example:
TRAIN:
quality 99% TEST:
quality 65%
The model works very well on what it has seen. But it generalizes poorly.
A simple analogy
A student:
"I will memorise all the answers from the textbook."
On the practice questions:
100%
On new ones:
badly
This is similar to overfitting.
27. Underfitting
The opposite problem:
Underfitting is when a model is too simple or not trained well enough, so it works poorly even on the training data.
For example:
flowchart LR
A["TRAIN"] --> B["badly"]
flowchart LR
C["TEST"] --> D["badly"]
The model simply failed to capture the pattern it needed.
Three situations
flowchart TD
A["UNDERFITTING<br/>the model is too simple"] --> B["bad on train"]
A --> C["bad on test"]
flowchart TD
A["GOOD FIT<br/>found a useful pattern"] --> B["good on train"]
A --> C["good on new data"]
flowchart TD
A["OVERFITTING<br/>adapted too much to train"] --> B["very good on train"]
A --> C["bad on new data"]
28. Data Leakage
This is a very important practical problem.
Data leakage is a situation where, during training or evaluation, the model receives information that it should not have had in a real situation.
A simple example
Suppose we want to predict:
Will the patient fall ill within the next month?
We use:
- age;
- blood pressure;
- test results.
But we accidentally included a feature:
"Whether the patient received treatment for this disease".
The problem is this:
if the treatment is prescribed after the disease has become known, then we have effectively given the model information from the future.
The model may show:
"Fantastic accuracy!"
But in real use this information is not known yet.
Why is leakage dangerous?
Because it creates the illusion:
"We have a magnificent model!"
while in fact the model received a hint that will not be there in a real situation. That is why data leakage can lead to very good results in testing and very poor results after deployment.
29. Quality metrics
Now we need to distinguish between:
loss and metric.
They are related, but they are not the same thing.
Metric
A metric is a numerical way to assess how well a model solves a task. For example:
How accurately do we predict prices?
or:
What percentage of emails are correctly classified as spam / not spam?
Why are the metrics different?
Because the tasks are different. For regression we can use:
- MAE — Mean Absolute Error;
- MSE — Mean Squared Error;
- RMSE — Root Mean Squared Error.
For classification:
- Accuracy — the share of correct answers;
- Precision — how precise the positive predictions are;
- Recall — completeness;
- F1-score — a combined measure of precision and recall.
Right now we do not need to derive these formulas. It is important to understand:
A metric answers the question: "How well does the model solve our task?"
30. Loss vs Metric
This is especially important.
Loss
Used as part of the model's training process.
flowchart TD
N1["prediction + target"] --> N2["loss"] --> N3["we change the parameters"]
Metric
Used to evaluate the quality of the model.
flowchart TD
N1["prediction + target"] --> N2["metric"] --> N3["how well does the model work?"]
Sometimes the same mathematical quantity can be used both as a loss and as a metric, but the roles of these concepts differ. You can remember it very roughly as:
Loss — what we steer by during training.
Metric — what we assess quality with.
This is not an absolutely universal rule, but for a first understanding it is very useful.
31. What does a "good model" mean?
A very important question. You might see:
TRAIN LOSS = very small
and say:
"The model is excellent!"
But that may be wrong. Why?
Because we are interested not only in:
how the model works on known data
but also in:
how it works on new data
That is:
flowchart TD
A["training performance"] --> B["how the model works during training"]
flowchart TD
C["generalization"] --> D["how it works on unseen data"]
flowchart TD
E["test performance"] --> F["an attempt to estimate this on an independent set"]
So a good model is not simply a model with a minimal training loss. We need a model that:
- learned well enough;
- did not overfit;
- generalizes well;
- shows good quality on data that was not used to fit it.
32. A typical ML pipeline
Now let us put together almost all of the material. A pipeline is a sequence of stages for processing data and building an ML solution.
A typical process might look like this:
Step 1. Formulate the task
For example:
We want to predict the price of an apartment.
Step 2. Collect the data
We find information about real apartments:
floor area
rooms
floor
neighbourhood
price
...
Step 3. Define the target
We decide:
What exactly do we want to predict?
The answer:
price
That is y.
Step 4. Choose the features
We decide what information to give the model:
floor area
rooms
floor
distance to the centre
That is X.
Step 5. Split the data
For example:
TRAIN
VALIDATION
TEST
Step 6. Choose a model
We choose a suitable algorithm. For now it is enough to know:
there are different kinds of models for different tasks.
Step 7. Train the model
The model receives the training data and selects parameters.
flowchart TD
N1["X + y"] --> N2["training"] --> N3["parameters"]
Step 8. Compute the loss
The model makes a prediction:
ŷ
We compare it with:
y
and compute the loss.
Step 9. Optimize the parameters
We want to reduce the loss. So the learning algorithm changes the parameters.
Step 10. Check validation
We check:
How well does the model work on data that was not used directly to select its parameters?
Step 11. Tune the hyperparameters
For example, we can change:
learning rate
or another setting of the algorithm. Then train and check the model again.
Step 12. Run the final test check
When development is finished, we look at the test set. This helps to obtain a more honest estimate of the final model.
Step 13. Use the model on new data
For example:
A new apartment has appeared.
We give its features to the model.
flowchart TD
N1["new apartment"] --> N2["model"] --> N3["predicted price"]
This is inference.
Step 14. Monitor quality after deployment
The world changes. Apartment prices may change.
The market may change. The relationships between the features may change.
That is why a real ML system is not necessarily:
"Trained once and forgotten."
The model needs to be monitored.
33. An end-to-end example: predicting an apartment price
Now let us deliberately go through the whole lecture once more, but as one continuous story. This is a very important section. Here the separate concepts should start to "click together".
Step 1. The real world
There are many real apartments.
Apartment #1
Apartment #2
Apartment #3
...
Step 2. Collect the data
For each apartment we write down:
floor area
rooms
floor
distance to the centre
price
Step 3. We get objects
Each apartment is an object. For example:
object #1 = an apartment with a floor area of 80 m²
Step 4. We get features
The object has:
area = 80
rooms = 3
floor = 5
distance = 4 km
These are the features.
Step 5. We get the target
The true price:
12,000,000 ₽
This is the target y.
Step 6. We get a dataset
Now we have thousands of rows:
| Area | Rooms | Floor | Distance | Price |
|---|---|---|---|---|
| 50 | 2 | 3 | 5 | 8M |
| 80 | 3 | 5 | 4 | 12M |
| 45 | 1 | 2 | 8 | 7M |
| 100 | 4 | 7 | 3 | 18M |
This is the dataset.
Step 7. Formulate the ML task
We want:
flowchart LR
N1["features"] --> N2["price"]
Since the price is a number:
this is a regression task.
And since we have the correct prices:
this is supervised learning.
Step 8. Split the data
For example:
flowchart LR
A["80%"] --> B["train"]
flowchart LR
C["10%"] --> D["validation"]
flowchart LR
E["10%"] --> F["test"]
This is an arbitrary example, not a universal rule.
Step 9. Train the model
The model receives:
X = features
y = true prices
and starts selecting parameters.
Step 10. Get a prediction
For example:
true price:
y = 12M
The model predicted:
ŷ = 10M
Step 11. Get the loss
We compare:
y
vs
ŷ
and get a loss value. The model is not predicting perfectly yet.
Step 12. Change the parameters
The learning algorithm changes the model's parameters so that its predictions become better. That is:
flowchart TD
N1["parameters"] --> N2["prediction"] --> N3["loss"] --> N4["new parameters"]
And the process repeats.
Step 13. Check validation
After training we check the model on data that it did not use for the direct selection of parameters. This helps to understand:
has the model really learned the pattern, or has it simply adapted too well to the training data?
Step 14. Check test
Once development is complete, we use the test set for the final evaluation.
Step 15. A new apartment arrives
For example:
area = 70 m²
rooms = 2
floor = 4
distance = 5 km
We do not know its future/real price. We only have:
X_new
We pass it to the trained model:
flowchart TD
N1["X_new"] --> N2["trained MODEL"] --> N3["ŷ_new"]
For example:
ŷ_new = 10.5M ₽
This is inference.
34. What machine learning does not mean
There are several widespread misconceptions about what machine learning (ML) does not mean. Let us go through each of them.
ML is not reducible to neural networks
Neural networks are only one class of models built with machine learning methods. Alongside them there are linear models, decision trees, ensembles, nearest-neighbour methods and many others. Machine learning as a field is far broader than neural networks.
Big data is not required
Some tasks really do require very large datasets — image recognition or training large language models, for example. But many ML tasks are solved successfully on comparatively small datasets: sometimes a few hundred or a few thousand examples are enough.
A GPU is not required
Some models and tasks work perfectly well on an ordinary processor, and they do not need a graphics card. Training large neural networks usually happens on a GPU, and the standard way to program such computations on NVIDIA hardware is the CUDA platform. But that is not the only path: AMD has ROCm, Apple has Metal, oneAPI and OpenCL exist for various accelerators, and TPUs are available in Google Cloud. On top of that, training — and especially inference — can run in the cloud on rented GPUs, or with no graphics card at all, on a CPU, if the model is small or compressed with quantization. Small models even run on phones and single-board computers.
The model does not understand the domain the way a human does
Even if a model predicts the price of an apartment well, that does not mean it "understands the real-estate market" the way a human does. It relies on mathematical relationships discovered in the data and does not possess a human understanding of the domain.
Supervised learning is not the only kind of learning
Beginners often think that machine learning means only tasks with ready-made correct answers, that is, supervised learning. In fact, the settings differ: supervised learning, unsupervised learning, semi-supervised learning and reinforcement learning. These are different problem settings, not subtypes of one: in some there are correct answers, in others there are none, and in others the model learns from its own actions and the reward it receives.
35. How this connects to the rest of our course
Now let us see why this lecture was needed at all.
flowchart TD
A1["Lecture 1<br/>intro to ML<br/>objects, features, loss"] --> A2["Lecture 2<br/>linear regression<br/>parameters, MSE"] --> A3["Lecture 3<br/>optimization<br/>gradient descent, SGD"]
flowchart TD
B1["Lecture 4<br/>optimization II<br/>AdaGrad, Adam"] --> B2["Lecture 5<br/>metric methods<br/>distances, KNN"] --> B3["Lecture 6<br/>logistic regression<br/>probabilities, log-loss"]
And now it is especially clear why lecture 1 was needed.
Lecture 1 said:
There is data → there is a task → we need a model → the model makes a prediction → the prediction can be wrong → we need a loss → we want to reduce the loss → we need to change the parameters → an optimization problem arises.
Lecture 2:
Let us now take a concrete model — linear regression.
Lectures 3–4:
Fine, we have a loss. How do we reduce it? Let us go through optimization.
Lecture 5:
Fine, and now let us look at another class of approaches — metric methods.
Now the course starts to look like a single system rather than a set of separate algorithms.
36. ML interview questions
First — questions only, without answers. After the lecture, try to answer them at least mentally.
Basics
- What is machine learning?
- How does ML differ from ordinary programming?
- Why is ML called learning?
- What is an object?
- What is a feature?
- What is a target?
- How does an object differ from its features?
- What is a dataset?
- What is a feature matrix?
- What is a target vector?
Types of tasks
- What is regression?
- What is classification?
- What is clustering?
- How does regression differ from classification?
- What is supervised learning?
- What is unsupervised learning?
- What is semi-supervised learning?
- What is reinforcement learning?
Model and training
- What is a model?
- What is a prediction?
- How does
ydiffer fromŷ? - What is a parameter?
- What is a hyperparameter?
- How does a parameter differ from a hyperparameter?
- What is training?
- What is inference?
- What happens during model training?
- What is loss?
- Why is a loss function needed?
- What is optimization?
Quality assessment
- What is a metric?
- How does loss differ from a metric?
- Why split the data into train and test?
- What is a validation set?
- What is a test set?
- Why can we not simply train a model and check it on the same data?
- What is generalization?
- What is overfitting?
- What is underfitting?
- How does overfitting differ from underfitting?
- What is data leakage?
- Why is data leakage dangerous?
The big picture
- What does a typical ML pipeline look like?
- What happens between the data and a prediction?
- Why does the need for optimization arise?
- What does "the model generalizes well" mean?
- What makes a good ML model?
37. Reference answers to the interview questions
Now you can check yourself.
1. What is machine learning?
Machine learning is an approach to building programs in which a model uses data to find patterns and then solves a task on new data.
2. How does ML differ from ordinary programming?
In ordinary programming the programmer specifies the rules explicitly:
flowchart LR
N1["rules + data"] --> N2["result"]
In ML we often provide the data and the correct answers, and the model selects its internal parameters itself:
flowchart LR
A["data + answers"] --> B["model"]
flowchart TD
C["model + new data"] --> D["prediction"]
3. What is an object?
An object is one unit of data, for example one apartment, one customer, one photograph or one email.
4. What is a feature?
A feature is a characteristic of an object that the model uses as input information. For an apartment this could be the floor area or the number of rooms.
5. What is a target?
The target is the target variable we want to predict. For an apartment-price prediction task the target is the price.
6. What is a dataset?
A dataset is a set of objects and the data associated with them that is used to solve an ML task.
7. How does classification differ from regression?
Regression predicts a numeric value. Classification chooses a class or a category.
For example:
flowchart TD
A["regression"] --> B["price = 12M"]
flowchart LR
C["classification"] --> D["spam"]
8. What is supervised learning?
Supervised learning is learning on data for which the correct answers y are known.
flowchart LR
N1["X + y"] --> N2["training"]
9. What is unsupervised learning?
Unsupervised learning is an approach in which the correct target answers are not known in advance, and the model looks for structure directly in the data.
10. What is a model?
A model is a mathematical or computational construction that turns input data into a prediction.
flowchart TD
N1["X"] --> N2["model"] --> N3["ŷ"]
11. What is a prediction?
A prediction is the result the model produces for the input data.
12. How does y differ from ŷ?
flowchart LR
A["y"] --> B["the true target"]
flowchart TD
C["ŷ"] --> D["the model's prediction"]
13. What is a parameter?
A parameter is an internal quantity of a model whose value is selected during training.
14. What is a hyperparameter?
A hyperparameter is a setting of the model or of the training process that is specified outside the model's direct selection of parameters.
An example is the learning rate.
15. What is loss?
Loss is a mathematical measure of how badly the model predicts. It links:
flowchart TD
N1["prediction + target"] --> N2["loss"]
16. What is training?
Training is the process during which the model receives data, makes predictions, computes the loss and changes its parameters.
17. What is inference?
Inference is applying an already trained model to new data in order to obtain a prediction.
18. Why is a test set needed?
To obtain a more independent estimate of how well the trained model works on data that was not used to fit it.
19. What is a validation set?
A validation set is used during development to compare model variants and tune hyperparameters.
20. What is generalization?
Generalization is the ability of a model to work well not only on the training examples but also on new data.
21. What is overfitting?
Overfitting is a situation where the model has adapted too strongly to the training data and therefore works poorly on new data.
22. What is underfitting?
Underfitting is a situation where the model does not describe the pattern well enough even in the training data.
23. What is data leakage?
Data leakage is information getting into training or evaluation that the model should not have had in a real situation.
24. What does an ML pipeline look like?
In general terms:
flowchart TD
A1["formulating<br/>the task"] --> A2["collecting data<br/>features and target"] --> A3["splitting<br/>the data"] --> A4["choosing<br/>a model"]
flowchart TD
B1["training<br/>evaluation"] --> B2["tuning<br/>testing"] --> B3["inference<br/>monitoring"]
38. Self-check exercises
Answer each task for yourself, then open the answer and compare. You do not have to solve it perfectly — the goal is to see where the gaps are.
Exercise 1. Features and target
Identify the features and the target.
A
We want to predict the price of a car from:
- make;
- year of manufacture;
- mileage;
- engine power.
B
We want to determine whether a bank transaction is fraudulent.
Name the feature and the target.
C
We want to predict tomorrow's temperature from weather data.
Name the feature and the target.
Show answer
A. Car price
Features:
make
year of manufacture
mileage
power
Target:
price
This is regression, because the price is a numeric value.
B. Fraudulent transaction
Features — the characteristics of the transaction. For example:
amount
time
place
type of operation
Target:
fraudulent / normal
This is classification.
C. Temperature
Features:
weather characteristics
Target:
temperature
This is regression.
Exercise 2. Type of task
Identify:
- regression;
- classification;
- clustering.
A
Predict a person's salary.
B
Determine whether a review is positive or negative.
C
Divide a store's customers into groups by behaviour.
D
Predict the delivery time of an order.
Show answer
| Task | Type |
|---|---|
| salary | regression |
| positive/negative review | classification |
| customer groups | clustering |
| delivery time | regression |
Exercise 3. Supervised or unsupervised?
A
There are photographs of cats and dogs, and each photograph has been assigned its correct class in advance.
B
There is data about customers, but it is not known in advance which groups they can be divided into.
C
There is historical data about apartments together with their prices, and we want to predict the price of a new apartment.
Show answer
A
photographs + correct classes
→ supervised learning
B
customers without ready-made groups
→ unsupervised learning
C
apartments + known prices
→ supervised learning
Exercise 4. Parameter or hyperparameter?
Identify what we are looking at:
A
The value of w, which the model selects during training.
B
The learning rate.
C
K in KNN.
Show answer
A
w:
→ parameter Because its value is selected by the model during training.
B
Learning rate:
→ hyperparameter
C
K in KNN:
→ hyperparameter
Exercise 5. Training or inference?
A
The model receives a training dataset and changes its parameters.
B
The trained model receives a photograph it has never seen before.
C
The model computes a prediction and a loss, after which the parameters change.
Show answer
A
training
Because the model is learning and changing its parameters.
B
inference
Because the trained model is applied to new data.
C
training
Because the computation of the loss is used in the training process, after which the parameters change.
Exercise 6. Where is the overfitting?
Consider the situations:
Model A
```text
train accuracy = 70%
test accuracy = 68%
```
Model B
```text
train accuracy = 99%
test accuracy = 61%
```
Model C
```text
train accuracy = 98%
test accuracy = 96%
```
Which situation looks most like overfitting?
Show answer
The obvious candidate:
Model B train = 99%
test = 61%
Why? The model works almost perfectly on the data it has seen, but much worse on new data.
This is a characteristic sign of overfitting.
Exercise 7. Why can we not train on the test set?
Explain in your own words:
Why would it be wrong to keep looking at the test set, changing the model and checking it again on the same test set?
Show answer
If you keep looking at the test set and changing the model on the basis of the test result, the test gradually stops being an independent check.
We effectively start tuning the model to the test set. Then a good result on the test set no longer means an honest estimate of the model's ability to work on completely new data.
Exercise 8. Data leakage
Come up with an example where information from the future accidentally gets into a prediction task.
Show answer
For example, we want to predict:
whether a person will be granted a loan.
We use:
age
salary
credit history
But we accidentally include:
the result of the bank's credit check
If that result appears after the decision is made, the model receives information that did not exist at the moment of prediction.
This is leakage.
Exercise 9. The full pipeline
Break the task down:
"We want to predict how long an order will take to be delivered."
into stages:
- object;
- features;
- target;
- dataset;
- ML task;
- training;
- prediction;
- loss;
- validation;
- test;
- inference.
Show answer
The task:
predict the delivery time of an order.
Object
One order.
Features
For example:
distance
time of day
day of the week
weather
delivery type
Target
The actual delivery time.
Dataset
Many historical orders with their features and their actual delivery time.
ML task
Regression, because time is a numeric quantity.
Training
The model receives the historical data and selects parameters.
Prediction
The model says:
expected time = 42 minutes
Loss
We compare:
the predicted 42 minutes
with the actual time.
Validation
We check the model on a separate part of the data during development.
Test
We finally evaluate the model on the test set.
Inference
A new order appears:
distance = 8 km
...
We feed it to the trained model and get:
ŷ = 42 minutes
48. The most important cause-and-effect chain
It is important to look at the logic, not at separate definitions. We start from the real world.
-
Objects exist in the real world
For example:
apartments↓
-
We collect data about the objects
floor area rooms floor ...↓
-
We get features
X↓
-
If we have the correct answer
For example:
pricethen we get:
y↓
-
Together we get a dataset
X + y↓
-
We want to solve an ML task
For example:
flowchart LR
N1["X"] --> N2["price"]
↓
- We need a model
flowchart TD
N1["X"] --> N2["MODEL"] --> N3["ŷ"]
↓
-
The model makes mistakes
ŷ ≠ y↓
-
We need a measure of the error
flowchart LR
N1["ŷ + y"] --> N2["LOSS"]
↓
-
We want to reduce the loss
LOSS ↓↓
-
For that we need to change the parameters
flowchart LR
N1["parameters"] --> N2["change"]
↓
-
This leads us to optimization
find good parameters↓
-
But working well on the training data is not enough
We need:
to work well on new data↓
-
This is generalization
↓
-
That is why validation and test are needed
↓
-
After training we get a finished model
↓
-
We give it new data
flowchart TD
N1["NEW DATA"] --> N2["MODEL"] --> N3["PREDICTION"]
↓
- This is inference
49. The final concept map
Now here is the big map that is really worth keeping in your notes.
Now literally every transition.
-
REAL WORLD → DATA
In the real world there are objects and events that we want to use to solve a task.
-
DATA → OBJECTS
We represent real entities as separate data examples.
-
OBJECTS → FEATURES
We describe each object with characteristics.
-
FEATURES → TARGET
If the task is supervised learning, the correct answers are known for the objects.
-
TARGET → DATASET
We assemble a set of objects, features and, where available, correct targets.
-
DATASET → ML TASK
We formulate what we want to predict or what structure we want to find.
-
ML TASK → MODEL
We choose a suitable mathematical/computational way to solve the task.
-
MODEL → PARAMETERS
The model contains internal parameters that affect its predictions.
-
PARAMETERS → TRAINING
During training the parameters are selected on the basis of the data.
-
TRAINING → PREDICTION
The model uses its current parameters to produce a prediction.
-
PREDICTION → LOSS
We compare the prediction with the target and get a measure of the error.
-
LOSS → OPTIMIZATION
If the loss is large, we want to find parameters at which it becomes smaller.
-
OPTIMIZATION → VALIDATION
We check how well the model works outside the immediate training examples.
-
VALIDATION → TEST
After development we run a final evaluation on a separate test set.
-
TEST → GENERALIZATION
The results on new data help to estimate the model's ability to generalize patterns.
-
GENERALIZATION → INFERENCE
If the model generalizes well enough, it can be applied to new real data.
-
INFERENCE → NEW DATA
A new object appears → the trained model receives its features → it produces a prediction.
50. A compact cheat sheet
This can already be copied out separately to the beginning or the end of your notes.
| Term | In short |
|---|---|
| ML | Machine learning — finding patterns in data in order to solve a task on new data. |
| Object | One specific object / data example. |
| Feature | A characteristic of an object used as the model's input. |
| Target | The correct answer we want to predict. |
| Dataset | A set of objects and the data associated with them. |
| X | The features of the objects. |
| y | The true target values. |
| Model | A computational construction that turns input data into a prediction. |
Prediction ŷ |
The answer the model produced. |
| Parameter | An internal quantity of a model selected during training. |
| Hyperparameter | A setting of the model/training specified outside the direct selection of parameters. |
| Loss | A mathematical measure of the error used in the training process. |
| Metric | A measure of the model's quality. |
| Training | The process of selecting a model's parameters from data. |
| Inference | Applying a trained model to new data. |
| Train set | The data on which the model is trained. |
| Validation set | Data for checking and tuning the model during development. |
| Test set | Data for the final independent evaluation. |
| Generalization | The ability to work well on new data. |
| Overfitting | The model adapted too much to the training data. |
| Underfitting | The model failed to capture the pattern well enough. |
| Data leakage | The model received information it should not have had. |
| Supervised learning | Learning with known correct answers y. |
| Unsupervised learning | Searching for structure without known targets. |
| Semi-supervised | Part of the data is labelled, part of it is not. |
| Reinforcement learning | Teaching an agent through actions and rewards. |
51. The most important thing to take away from the lecture
If half of the English terms are forgotten after this lecture — that is normal. What matters to me much more is that this story stays in your head:
Data
flowchart TD
A1["There are objects in the real world"] --> A2["We collect data"] --> A3["An object: a flat"] --> A4["Features: area, rooms, floor"]
Goal and task
flowchart TD
B1["Target: the price"] --> B2["Dataset"] --> B3["ML task: predict the price"] --> B4["Model"]
Prediction and loss
flowchart TD
C1["Features X → prediction ŷ"] --> C2["Compare with the answer y"] --> C3["Loss function"]
Training
flowchart TD
D1["Reduce the loss"] --> D2["Update the parameters"] --> D3["Optimization"]
Check and inference
flowchart LR
E1["Generalization"] --> E2["Overfitting"]
E1 --> E3["Underfitting"]
E1 --> E4["Inference"]
And all of it can be compressed into literally one chain:
The most important thing to understand:
There is data → we want a prediction → we need a model → the model can be wrong → we need a measure of the error (loss) → we want to reduce the error → we change the parameters → we train the model → we check whether it can generalize the pattern → we apply it to new data.
This is the skeleton of machine learning, onto which mathematics, algorithms and concrete models will gradually be hung. And lecture 2 — linear regression will now be not "a new pile of terms", but the first concrete answer to the question:
"Fine. What is this MODEL we have been talking about all along, and how exactly does it make a prediction?"
After it, lecture 3 and lecture 4 will naturally answer the next question:
"Fine. We have a loss. But how exactly do we change the parameters so that the loss decreases?"
And with this fundamental picture already in place, lecture 5, "Metric Methods", will be perceived as the next way to solve ML tasks rather than as a set of unknown words.
🧪 Practice
- Descent on the loss function — a ball rolls down a real loss landscape: you can see where the gradient comes from and why the learning step cannot be taken too large.
- Fit a line by hand — drag a line across a cloud of points and watch the error change: this is "training a model" in its simplest form.
- Polynomial degree: overfitting — a slider for model complexity: the error on train always falls, while on new data it first falls and then rises.
- Embeddings, PCA and k-means — 303 objects in a 16-dimensional space: a visual take on the idea that an object is a point in feature space.
Check yourself
📚 Further reading
- Loss Functions — an overview of loss functions and what they mean.
- Overfitting and Regularization — what to do when a model memorises instead of understanding.
- Model Quality Assessment — how quality is measured on new data.







