🎯 Welcome to Section 5. Everything so far — NumPy arrays, pandas DataFrames, Matplotlib/Seaborn charts, and the statistics from Section 4 — was about understanding data that already happened. Machine learning is about using that data to make predictions about things you haven't seen yet. This lesson lays the vocabulary and mental model the rest of the section builds on: what ML actually is, the three broad families of ML problems, classification vs regression, the standard workflow every model follows, and the single most important failure mode to watch for — overfitting.
Section 1
What Is Machine Learning, Really?
In traditional programming, a human writes explicit rules, and the computer applies those rules to data to produce answers. Machine learning flips that around: you give the computer data and the answers that go with it, and it works out the rules — called a model — on its own.
Traditional Programming vs. Machine Learning
Rules + Data → Answers ⟷ Data + Answers → Rules
Traditional code runs rules a human wrote. A trained ML model IS the rules — learned automatically from examples, then reused to predict answers for new data the model has never seen.
Think of spam detection. Writing explicit rules like "block any email containing the word FREE" breaks quickly — spammers adapt, and legitimate emails use that word too. Instead, an ML model is shown thousands of emails already labeled spam or not-spam, and it learns the statistical patterns that separate the two — patterns far too subtle and numerous for a human to hand-write as rules.
📝
"Learning" here means finding parameters, not gaining understanding
When people say a model "learns," they mean an algorithm is searching for the numeric parameters (like the slope and intercept from Lesson 22's line of best fit) that make its predictions match the known answers as closely as possible. There's no comprehension involved — it's optimization, applied at a much larger scale than a single straight line.
Section 2
Three Types of Machine Learning
Almost every ML problem falls into one of three broad categories, depending on what kind of data and feedback the model has access to.
🏷️
Supervised Learning
Trained on labeled data — every example comes with the correct answer attached.
🔍
Unsupervised Learning
Trained on unlabeled data — the model finds structure or groups on its own.
🎮
Reinforcement Learning
An agent learns by trial and error, guided by rewards and penalties.
1
Supervised learning — Sections 5 lessons 25–27, and the final project
You give the model input features (X) AND the correct output (y) for every training example — like house size paired with actual sale price. The model learns to map X to y, then predicts y for new X it hasn't seen. This is the category the rest of this section focuses on.
2
Unsupervised learning — Lesson 28
You give the model only the input features, with no correct answer attached. It looks for structure on its own — for example, grouping similar customers together without ever being told what the "right" groups are. K-Means clustering in Lesson 28 is the classic example.
3
Reinforcement learning — mentioned for completeness
An agent takes actions in an environment (like a game or a robot navigating a room) and receives rewards or penalties. Over many attempts it learns a strategy that maximizes reward. This course doesn't build a reinforcement learning model, but it's worth knowing the name and the idea, since it's the family behind things like game-playing AI.
✨
The labels are the whole difference
If your dataset has a clear "answer column" you're trying to predict (a price, a category, a yes/no) — that's supervised learning. If it doesn't, and you're instead looking for patterns or groupings within the data itself — that's unsupervised. Reinforcement learning is a different setup entirely: there's no fixed dataset at all, just an agent interacting with an environment over time.
Section 3
Classification vs. Regression
Within supervised learning, there are two sub-types, split by what kind of answer you're predicting.
🏷️
Classification
Predicts a category or class — spam/not-spam, pass/fail, or which of several species a flower belongs to. The output is one of a fixed, finite set of labels.
📈
Regression
Predicts a continuous number — a house price, an exam score, tomorrow's temperature. The output can, in principle, be any value on a number line.
⚖️
Binary classification
The special, very common case of classification with exactly two possible classes — e.g. "will this loan default: yes or no." Lesson 25's logistic regression is built for exactly this.
🔢
Same features, different targets
The exact same input features (study hours, attendance) could feed either a regression model predicting an exact exam score, or a classification model predicting pass/fail — the choice depends on what question you're asking.
⚠️
"Regression" here doesn't mean what Lesson 22 might suggest
Lesson 22 introduced linear regression as a statistics tool for fitting a line. In machine learning, "regression" is used more broadly as the name for the entire task of predicting a continuous number — linear regression is just one algorithm (among several, including the tree-based models in Lesson 26) that can be used to solve a regression task.
Section 4
The Typical ML Workflow
Nearly every supervised learning project in scikit-learn — regardless of which algorithm you pick — follows the same five-step shape. You'll see this exact pattern repeat in every remaining lesson of this section.
1
Split the data
Divide your dataset into a training set (the model learns from this) and a test set (held back, used only to check performance afterward) — with train_test_split().
2
Choose a model
Pick an algorithm — LinearRegression, LogisticRegression, DecisionTreeClassifier, and so on — and create an instance of it.
3
Fit the model
Call .fit(X_train, y_train) — this is the actual "learning" step, where the model finds parameters that match the training data.
4
Predict on new data
Call .predict(X_test) to generate predictions on data the model never saw during training.
5
Evaluate
Compare the predictions to the real answers (y_test) with an appropriate metric — Lesson 25 covers regression metrics, Lesson 27 covers classification metrics in depth.
ml_workflow_preview.py
PYTHON
from sklearn.model_selection import train_test_split
import numpy as np
# X must be 2D: one row per example, one column per feature
X = np.array([[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]])
# y is 1D: one target value per example
y = np.array([2, 4, 5, 4, 5, 7, 8, 9, 10, 12])
# Step 1 — split into train and test (80% / 20% here)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
print("Train size:", len(X_train), "| Test size:", len(X_test))
# Steps 2-5 use an actual model class — LinearRegression is coming up in Lesson 25.
# The shape below — .fit(), then .predict(), then compare to y_test — never changes.# model = LinearRegression()# model.fit(X_train, y_train)# predictions = model.predict(X_test)
📝
Why bother splitting the data at all?
If you evaluated a model on the same data it trained on, you'd be testing its memory, not its ability to generalize. random_state=42 fixes the random shuffle so the split is reproducible — anyone running this exact code gets the exact same train/test rows.
Section 5
Overfitting vs. Underfitting
This is the single most important idea to internalize before training any model. A model's real job is to perform well on new data — not to perfectly memorize the data it was trained on.
🎓
The exam-studying analogy
Imagine a student preparing for an exam using last year's practice test. One student memorizes the exact answers to every practice question, word for word — they'll ace a repeat of that exact test, but bomb the real exam the moment a single question is phrased differently. Another student barely studies at all — they'll do poorly on both the practice test and the real exam. The student who does best on the real exam is the one who understood the underlying concepts well enough to generalize to questions they hadn't seen before. A good ML model is that third student.
📚
Overfitting
The model memorizes the training data too closely — including its noise and quirks. Result: great performance on the training set, poor performance on new (test) data.
😴
Underfitting
The model is too simple to capture the real pattern in the data at all. Result: poor performance on both the training set AND the test set.
🎯
The goal: good generalization
A well-fit model performs similarly — and reasonably well — on both the training set and the test set. That similarity is the signal you're looking for, not a single "high accuracy" number in isolation.
🌡️
Model complexity is the dial
Overfitting and underfitting usually sit at opposite ends of a "model complexity" dial — Lesson 26 shows this directly with decision tree depth: too shallow underfits, too deep overfits.
⚠️
A model that's perfect on the training set is a warning sign, not a triumph
If a model scores 100% on training data but noticeably worse on test data, that gap is the fingerprint of overfitting. This is exactly why Step 1 of the workflow above — holding out a separate test set — exists: without it, overfitting would be invisible until the model failed in the real world.
🧩 Knowledge Check — Lesson 24
3 questions on the core ML vocabulary before you move on.
1. A model is trained on customer purchase data with NO labels attached, and it groups customers into clusters on its own. What type of learning is this?
2. A model predicting "will this email be spam or not-spam" is doing which kind of task?
3. A model scores 99% accuracy on its training data but only 61% on its test data. What does this gap most likely indicate?
💪
Try It Yourself — Lesson 24
Get comfortable with the vocabulary · Beginner Level
No sklearn model to train yet — this section's task list is about locking in the concepts, plus one hands-on look at train_test_split().
Task 1: Classify three real-world problems 🏷️
For each of these, decide whether it's supervised or unsupervised, and if supervised, whether it's classification or regression: (a) predicting a car's resale price from its mileage and age, (b) grouping news articles into topics without pre-defined categories, (c) predicting whether a tumor is malignant or benign from scan measurements.
Task 2: Experiment with train_test_split() 🔀
Using the X and y arrays from Section 4's code sample, call train_test_split(X, y, test_size=0.3, random_state=1) and print the resulting X_train and X_test. Then run it again with a different random_state value — confirm the split changes.
Task 3: Spot the overfitting story 📉
In your own words, write two or three sentences describing a model that is overfitting, using the exam-studying analogy from Section 5 as your template but applied to a completely different everyday situation (not exams).
💡 Show hints if you're stuck
Task 1: (a) supervised, regression — the target is a continuous price. (b) unsupervised — no pre-defined labels exist. (c) supervised, classification — the target is one of two categories.
Task 2: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1) — with 10 total examples and test_size=0.3, expect 7 training rows and 3 test rows.
Task 3: A good analogy has the same shape as the exam one: something performs suspiciously well on a familiar situation, but poorly the moment conditions change even slightly — e.g. someone who memorizes a specific driving route perfectly but gets lost the moment a road is closed.
Finished this lesson?
Mark it complete to track your progress.
🎉
Lesson 24 Complete!
You now have the vocabulary that every remaining lesson in this section leans on — supervised vs. unsupervised, classification vs. regression, the fit/predict workflow, and overfitting vs. underfitting. Next: your first real scikit-learn models.
Module 24 of 30
Section 5 — Machine Learning with Scikit-Learn