Predicting numbers and choosing categories
Understand the two most common prediction jobs in machine learning: estimating a value and assigning a label.
Before We Begin
A large share of introductory machine learning reduces to two questions. Regression asks 'how much?' and classification asks 'which category?'. Even when later models become more complex, they often still boil down to one of these two prediction styles.
How this lesson fits
This module is where the course shifts from explicit rules to learned patterns. Instead of telling the machine exactly what to do in every case, we give it examples, define success, and let it infer a decision rule from the data.
The big question
How can a machine study examples, extract useful patterns, and make predictions on cases it has never seen before?
Why You Should Care
Students who can clearly separate these two task types are much less likely to misuse models or misread outputs. It also creates a sturdy foundation for understanding loss functions, metrics, and later neural-network examples.
Where this is used today
Think of it like this
If you are estimating the selling price of a house, you are doing regression. If you are deciding whether an email is spam or not spam, you are doing classification. One output is continuous, the other is categorical.
Easy mistake to make
Logistic regression is confusingly named. In most practical settings it is used as a classification model because it estimates class probabilities rather than arbitrary numeric values.
Think about this first
Which task is regression and which is classification: predicting a student's exact exam score, or predicting whether they will pass the course? Explain the difference in the expected output.
Words we will keep using
Linear regression asks: "What is the number?" (e.g., price, temperature). It tries to draw a straight line that passes as close as possible to all your data points.
To find the best line, the computer plays a game of "hot or cold." It nudges the line slightly, checks if the error gets smaller, and repeats. This process is called gradient descent.
Try a large learning rate (Ξ± β 0.04) and watch the loss. Too large β oscillation; too small β slow convergence.
Logistic regression asks: "Yes or No?" (e.g., Spam or Not Spam). Instead of a raw number, it gives you a probability between 0% and 100%.
Drag the sliders and watch the decision boundary move. That boundary is the place where the model is exactly undecided, with .
Notice the limitation: logistic regression can only draw a straight dividing line. If the pattern is curved, we need a more flexible model.
Accuracy is a trap. If 99% of emails are safe, a model that says "Safe" every time is 99% accurate but 100% useless at catching spam. We need better scoreboards.
The four cells
TP (True Positive) β correctly predicted positive
FP (False Positive) β predicted positive, actually negative (Type I error)
FN (False Negative) β predicted negative, actually positive (Type II error)
TN (True Negative) β correctly predicted negative
Accuracy = (TP+TN) / N. Fine when the classes are balanced, but risky when one class is rare.
Precision = TP / (TP+FP). When you say βpositive,β how often are you right?
Recall (TPR) = TP / (TP+FN). Of the real positives, how many did you actually catch?
F1 combines precision and recall into one score when both matter.
ROC-AUC measures ranking quality across many thresholds, not just one fixed cutoff.
Drag threshold β watch the orange dot move along the curve
Model parameters
Confusion Matrix
| Pred + | Pred β | |
|---|---|---|
| Actual + | TP = 18 | FN = 22 |
| Actual β | FP = 18 | TN = 22 |
Live metrics at t = 0.50
Accuracy
50%
Precision
50%
Recall
45%
F1 Score
47%
When classes are imbalanced
If one class is rare, accuracy can hide failure. In those cases, precision, recall, F1, and PR-AUC usually tell a more honest story.
Threshold trade-off
If you lower the threshold, the model says βpositiveβ more often. That usually helps recall but hurts precision. You are trading one kind of mistake against another.
Beyond binary classification
Different tasks need different scoreboards. There is no single metric that is best for every problem.
When the output is a number, the question becomes: how far off were we? That is why regression uses error-based metrics instead of a confusion matrix.
Mean Absolute Error β robust to outliers, interpretable in original units
Mean Squared Error β penalises large errors heavily; used as training loss
Root MSE β same units as target, more interpretable than MSE
RΒ² (coefficient of determination) β proportion of variance explained. 1.0 = perfect, 0 = no better than predicting the mean