What machine learning is
What it is
Instead of writing the rule that maps an input to an output, you supply examples of inputs paired with correct outputs and let an algorithm search for a function that reproduces them. The program is the fitted function; the code you write only describes the search.
Why it matters
It changes where the work goes. In rule-based software the hard part is expressing the logic; in ML the logic is inferred, so the hard parts become the data, the choice of what to predict, and checking that the inferred rule holds on examples it never saw.
In the real world: Instead of hand-writing rules for spam, an email provider shows a model millions of labelled emails and lets it learn the patterns.
Visual example
Supervised learningLearning turns labelled examples into a function. The examples are the specification; the fitted function is the program.
Why this matters
It locates the leverage. Two weeks spent improving the labels in the left-hand table moves the result more than two weeks spent swapping the algorithm that produced the right-hand one.
Common misconception
Wrong idea: the model contains the data it was trained on, and prediction is a lookup.
Correct idea: training compresses the examples into a handful of parameters. The rows are gone; only the fitted function remains, which is exactly why it can answer about rows it never saw — and why it can be wrong about them.
- 1Examples inEach row is one input with its known correct answer.
- 2SearchThe algorithm adjusts parameters to reduce error on those rows.
- 3Function outWhat ships is the parameters, not the table.
The algorithm never sees your intent — only these rows. Whatever pattern is in them is the pattern it learns.
# Hand-coded rule: you state the logic.
def is_spam(subject, n_links):
return "free" in subject.lower() and n_links > 3
# Learned rule: you state examples, the algorithm finds the logic.
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train) # X: features per email, y: 0/1 spam
model.predict(X_test[:5]) # the learned rule, appliedReaching for ML when a rule would do. If the mapping is known, short, and stable — tax brackets, a validity check — a learned model is strictly worse: it is approximate, it needs data, and it can drift. ML earns its place when the rule is unknown, long, or changing.