ML-01-001-P · Primer — What Is Machine Learning? Supervised Learning in One Idea
The idea in one sentence
Machine learning is the trick of showing a program examples and letting it figure out the rule for itself, instead of you writing the rule by hand.
Why it exists
Some tasks are easy to describe with rules: "if the total is over $100, add free shipping." You can type that if statement in five seconds. But now try to write the rules for "is this email spam?" or "will this student pass the exam?" You'd need hundreds of tangled conditions, and you'd still miss cases you never thought of. The world is messy, and hand-coded rules are brittle. Machine learning flips the problem around: instead of you inventing the rule, you collect a pile of examples where you already know the answer — emails you've labeled spam/not-spam, students whose pass/fail you recorded — and a learning algorithm searches for the pattern that maps inputs to those answers. When the pattern generalizes, it correctly answers new examples it has never seen. That last part is the whole game, and it's why ML powers so much of modern software.
How it works
The setup has three pieces: features (the inputs, X — what you know), labels (the correct answers, y — what you want to predict), and a model (the algorithm that learns the mapping from X to y). This particular flavor — where every training example comes with its correct label — is called supervised learning, because the known answers "supervise" the learning, like an answer key. You call .fit(X, y) to learn from examples, then .predict(...) to answer new questions. Below, each student is described by one feature (hours studied) and one label (did they pass?); the model learns roughly "study more → more likely to pass," then predicts for two brand-new students.
from sklearn.linear_model import LogisticRegression
import numpy as np
# features X: hours studied labels y: passed the exam? (1 = yes, 0 = no)
X = np.array([[1], [2], [3], [4], [5], [6], [7], [8]])
y = np.array([ 0, 0, 0, 0, 1, 1, 1, 1 ])
model = LogisticRegression()
model.fit(X, y) # learn the mapping from examples
new_students = [[4.5], [6.5]] # two students we've never seen
print(model.predict(new_students)) # -> [0 1] (4.5h: fail, 6.5h: pass)
print(model.score(X, y)) # -> 1.0 (100% correct on this data)
The model never saw a rule like "5 hours is the cutoff" — it discovered the boundary from the eight examples, then applied it to the two new students on its own.
The one gotcha
A perfect score of 1.0 here is a warning sign, not a trophy. We scored the model on the same examples it studied, which is like grading a test using the answer key the student already memorized — of course it's perfect. The real question is how it does on data it has never seen, and this tiny toy dataset is far too small and clean to trust. Always keep a separate test set (and never let it leak into training); that discipline is what separates a model that learned the pattern from one that just memorized the examples.
See it — supervised learning: from examples to predictions
flowchart TD A["Examples with answers<br/>(features X + labels y)"] --> B["fit(X, y):<br/>learn the mapping"] B --> C["Trained model<br/>(the learned rule)"] D["New input<br/>(features only)"] --> E["predict(new):<br/>apply the rule"] C --> E E --> F["Answer<br/>(predicted label)"]
The one-line takeaway
Don't write the rule — collect labeled examples and let fit learn the rule, then predict new answers.
Where you'll meet it
Every time an app filters spam, flags fraud, recommends a movie, estimates a house price, or reads a photo's contents, some supervised model was fit on labeled examples first. It's the workhorse of applied ML and the foundation for everything in the deep AIM track — classification, regression, train/test splits, and beyond all start from this one idea.
Named concepts: machine learning vs rules, supervised learning, learning from examples
