Skip to content

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

Ordinary code: you supply the rules; the data flows through and answers come out. Machine learning: you supply the data and its answers, and out comes the rule. Same three pieces - rules, data, answers - but you feed in a different two and ask the machine for the third.

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.

Spam filter: rules vs. learningmode: write a rule
↑ ALL-CAPS wordslinks per email →
spamsafe (not spam)misclassified

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

Your two hand-tuned thresholds can only carve out a rectangle - a corner of the plane. But spam and safe mail actually split along a diagonal, and no pair of straight thresholds can trace a diagonal. The learned boundary faced no such limit: it looked at where your labelled examples land and tilted itself to match. You labelled a handful; it correctly sorted all twenty - including the ones you never touched. That is generalization, and it is why learning-from-examples beats hand-coding when the pattern is even mildly complex.

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 input

When ML is the wrong tool

Learning isn't a free upgrade. Reach for plain code when the rule is already known and simple (convert Celsius to Fahrenheit - just write the formula), when you have too few labelled examples to learn from, or when you need an exact, auditable guarantee rather than a statistical "usually right." ML shines only when the pattern is real but too tangled to write out by hand - like spam, faces, or language.

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

The gentlest rigorous on-ramp is Andrew Ng's Machine Learning Specialization (audit it free), which opens with exactly this "learn a function from examples" framing. For visual intuition about what that learned function is on the inside, nothing beats 3Blue1Brown's Neural Networks series.

Ask your teacher

This lesson is the doorway to the whole LLM path: a large language model is just a very large learned function - the same , only with billions of tunable numbers and text for . The obvious next question is how the machine actually adjusts to fit the examples. That mechanism is gradient descent, and we build it from scratch in Lesson 11. Curious where the "adjusting" comes from before then? Ask, and I'll sketch the intuition early.