What Learning Means
What is machine learning?
Fitting a function from examples, not rules
The one mental flip that separates ordinary programming from ML - and the doorway to every neural network and language model you'll ever build.
You already know how to program: you write the rules, the computer follows them. Machine learning inverts that. You stop writing rules and instead hand the machine a pile of labelled examples - "this email is spam, this one isn't" - and it figures out the rule for you. That single inversion is the whole idea. Everything else in this path is detail on top of it.
The one mental flip
The function you're trying to find
Every ML task hides the same shape. You have some input - the features that describe one thing (an email's link count, its number of ALL-CAPS words). You have a desired output - the label (spam or not). Learning means searching for a function that maps one to the other:
The is the entire game. You don't want an that merely memorises your examples - you want one that keeps working on inputs it has never seen. That property is called , and it's the difference between a model that's useful and a lookup table that isn't.
See it: hand-coded rules vs. a learned rule
Below are 20 emails plotted by two features: links across the bottom, ALL-CAPS words up the side. Red dots are spam, green are safe. Start in Write a rule and drag the two thresholds to catch the spam - you are the programmer. Then switch to Let it learn: hand the machine just a few examples and watch it draw its own boundary. Compare the accuracy.
Hand-rule accuracy: 70% - 6 of 20 emails misclassified. Slide all you like: two straight thresholds can't trace a diagonal split.
Why the learned rule wins
Two phases: training and inference
Every model lives in two modes, and it's worth naming them now because you'll meet them on every page from here on:
- Training - the one-time, expensive phase where the machine sees labelled examples and adjusts the function to fit them. This is "the learning."
- Inference - the cheap, repeated phase where you feed a fresh into the finished and read off a prediction . This is "using the model."
In code, the flip looks like this - notice who writes the decision:
# Ordinary code: YOU write the rule
def is_spam(email):
return email.links > 5 and email.caps > 5 # you picked these thresholds by hand
# Machine learning: the DATA writes the rule
model = train(labelled_emails) # TRAINING: learn f from examples
prediction = model.predict(new_email) # INFERENCE: apply f to unseen inputWhen ML is the wrong tool
Check yourself
In machine learning, what does the developer supply instead of the rules?
What makes a learned model actually useful - its real goal?
Recall: in one sentence, how is machine learning different from ordinary programming?
Tie the inversion back to the function you are searching for. Try to state it, then check.
Primary source
Ask your teacher