Supervised learning
Обучение с учителем
This is a way to train a model using examples with known answers. The model learns to predict answers for new examples, such as whether an email is spam or how long a delivery will take.
Also known as: обучение без учителя, unsupervised learning
What the model learns from
Suppose you want to predict delivery times at checkout. For past orders, you know both what was in the cart at checkout and how long delivery actually took. The checkout information provides the features: inputs the model can use to make a prediction. The elapsed time provides the target: the outcome you want the model to predict. That's what makes the learning supervised. The answers don't have to come from human annotators; they can come from records of what happened.
Predicting a category, such as whether a package will arrive late, is classification. Predicting a quantity, such as the number of minutes until delivery, is regression. Unsupervised learning isn't another name for supervised learning. For example, clustering can group similar orders without being given a correct group for each one.
From historical records to predictions
- Define the prediction point. If the estimate appears at checkout, use features available then, such as the delivery zone and time of day. Use the actual delivery time to calculate the target, not as a feature.
- Split and fit. Train on one part of the data and use a validation set to compare models or tune settings. For a service that predicts future orders, a chronological split is usually more realistic than a random one. During training, the algorithm uses a loss function to measure prediction errors and fit the model.
- Evaluate on a held-out test set. Once you've made your modeling choices, use the test set to estimate performance on unseen examples. For delivery times, mean absolute error tells you how many minutes the predictions are off by on average.
A baseline you can check by hand
Before trying a complex model, predict the same value for every order: the median delivery time in the training data. If that median is 30 minutes and two test orders took 25 and 45 minutes, the absolute errors are 5 and 15 minutes, so the mean absolute error is 10 minutes. A more complex model should beat the baseline on representative data before you rely on it. You might also check busy periods separately: one average can hide larger errors during the dinner rush.
Common mistakes and interview scenarios
Supervised learning also powers spam filters, defect detection, and demand forecasts. In an interview, you may be given one of these problems and asked to define the target, choose a data split, and defend a metric. Start with how the prediction will be used. For a spam filter, accuracy can look excellent even if the model ignores spam entirely: if only 1% of emails are spam, calling everything legitimate gives 99% accuracy. Precision and recall show, respectively, how often spam flags are correct and how much of the actual spam the filter catches.
Watch for data leakage, which happens when training or evaluation uses information that wouldn't be available in the real prediction setting. For instance, using a status recorded after delivery can make a checkout estimate look unrealistically good. That's different from overfitting, where a model learns quirks of the training data that don't carry over to new examples.
“Supervised learning” questions from real interviews
Asked at 8 companies