Skip to content
learn
  1. Learn
  2. Machine Learning
  3. Orientation

Machine Learning ML-00.01

What is machine learning?

See how machine learning flips ordinary programming: instead of writing rules, you show examples and let the computer find the rules itself.

Beginner 10 min Last reviewed

The big idea

Suppose you have to write a program that decides whether an email is spam. The obvious approach is to write rules: if the subject contains "FREE MONEY", it is spam. If there are more than five links, it is spam. You ship it, and next week spammers write "FR33 M0NEY" and use four links. You add more rules. Then more. Within a month you have hundreds of fragile rules, and it still misses half the spam.

Machine learning takes a different route. Instead of writing the rules yourself, you collect thousands of emails that people have already marked as spam or not spam, and you let the computer work out the rules from those examples. When spammers change tactics, you do not rewrite code. You show it new examples and let it learn again.

That is the whole shift: ordinary programming is you telling the computer how to decide. Machine learning is you showing the computer what good decisions look like, and letting it figure out how.

Think of how a child learns what a dog is. Nobody hands them a rulebook ("four legs, fur, a tail, barks"). Cats break that rulebook immediately. Instead, the child sees many dogs and many non-dogs, gets corrected a few times, and somewhere along the way builds an internal sense of "dog" that works even for breeds they have never seen.

How it works

Step 1: Rules in, or rules out

In traditional programming, a person writes the rules, the program applies them to data, and answers come out. In machine learning, you supply the data together with the answers you want, and the training process produces the rules. Those learned rules are called the modelThe function a machine learning algorithm produces from training data. It maps inputs to predictions..

Traditional programming versus machine learning Top: a person writes rules, and a program combines the rules with data to produce answers. Bottom: data and the correct answers go into training, and training produces the rules, which is the model. traditional programming machine learning Rules written by a person Data Program Answers Data Answers the examples Training Rules the model Figure 1. Traditional programming turns rules plus data into answers. Machine learning turns data plus answers into rules: the arrows reverse.

Once you have a model, you use it like any other function: give it a new email and it returns "spam" or "not spam". The difference is that nobody typed its logic. It was learned.

Step 2: The five words you need

Every lesson in this track uses the same five words. Here they are with the spam filter as the example.

  • FeatureOne measurable input to a model, such as the number of links in an email or a house's floor area.: one input the model looks at. For an email: the number of links, the words in the subject, whether the sender is in your contacts.
  • LabelThe correct answer for a training example, such as spam or not spam, or the price a house sold for.: the right answer for an example. Here: spam or not spam.
  • Model: the learned function from features to a prediction.
  • TrainingThe process of adjusting a model's internal numbers so its predictions on known examples match their labels.: showing the model many labeled examples and adjusting its internal numbers until its predictions match the labels as often as possible.
  • InferenceUsing a trained model to make a prediction on new data it has not seen.: using the trained model on new, unlabeled data. Every time your inbox sorts a fresh email, that is inference.

Training is slow and happens occasionally, often offline. Inference is fast and happens all the time, often millions of times a day. Keeping that split in mind explains a lot of how ML systems are built.

Step 3: AI, machine learning and deep learning

People use these three terms loosely, but they nest inside each other.

AI contains machine learning, which contains deep learning Three nested circles. The outer circle is artificial intelligence, any technique that makes computers behave intelligently. Inside it is machine learning, which learns from data. Inside that is deep learning, which uses neural networks with many layers. Artificial intelligence computers acting smart, by any method Machine learning learning from examples Deep learning many-layer neural networks chess engines with hand-written search spam filters, price predictors Figure 2. Deep learning is one kind of machine learning, and machine learning is one route to AI.
  • Artificial intelligenceThe broad field of making computers do things that seem to require intelligence, by any method, learned or hand-coded. is the widest circle: any technique that makes a computer act intelligently. A chess program that searches millions of moves using rules written by people counts, even though it learns nothing.
  • Machine learning is the part of AI that learns from data instead of following hand-written rules.
  • Deep learningMachine learning with neural networks that have many layers, which learn their own features from raw data such as pixels or text. is the part of ML that uses neural networks with many layers. It powers image recognition, speech recognition and large language models. You will build one in The perceptron and the artificial neuron .

Step 4: You already use it every day

  • Spam filters learn from millions of messages people marked as spam.
  • Recommendations ("people who watched this also watched") learn from what users clicked, watched and skipped.
  • Map arrival times learn from the real travel times of past trips at that hour, on that road, in that weather.
  • Phone keyboards learn which word you probably meant to type next.

Each one has the same shape: lots of past examples with known outcomes, and a model that predicts the outcome for the next case.

Try it

You are going to be the person who labels the training data. Each dot is an email, placed by two features: how many links it contains (left to right) and how many words are in ALL CAPS (bottom to top).

Click a dot to label it. Clicking again cycles: not spam, spam, unlabeled.
links in the message words in ALL CAPS
Label at least one of each kind to train.

not spam spam unlabeled. The shaded background is the model's guess for every possible message.

Try this:

  1. Label the three dots nearest the bottom-left as not spam and the three nearest the top-right as spam. Watch a boundary appear and the background shade show the model's guess for every possible email.
  2. Press "New message arrives" a few times. The star is an email the model has never seen. Its prediction is inference: no new training, just applying what it learned.
  3. Mislabel one dot on purpose (a spam-looking email marked not spam) and watch how much the boundary bends to accommodate one bad label. Labels are the model's only teacher.

Trade-offs

OptionWins whenLoses when
Hand-written rules The logic is simple, stable and must be fully explainable, such as tax calculations or input validation The pattern is fuzzy or changes often, like spam, fraud or images
Machine learning You have many past examples with known answers and the pattern is too complex to write down You have little or no labeled data, or a mistake is unacceptable and must be explainable rule by rule
Both together Rules handle hard constraints and obvious cases, a model handles the fuzzy middle Two systems to maintain, and their interaction needs testing

Common mistakes

  • Reaching for ML when a few clear rules would do. If you can write the logic in ten lines, write it.
  • Thinking the algorithm is the hard part. Most of the work, and most of the quality, is in the data and labels (you will see why in The ML project lifecycle ).
  • Treating "AI" and "machine learning" as the same thing. All ML is AI, not all AI is ML.
  • Forgetting the training versus inference split: a model that takes ten seconds per prediction may be fine to train but useless at inference time.

In the wild

You meet machine learning dozens of times a day without noticing. Email providers filter spam with models retrained on fresh reports, streaming services order your home screen with recommendation models, map apps predict arrival times from past trips, banks score card transactions for fraud in milliseconds, and phone cameras use deep learning to find faces before you press the shutter. Every one of those systems was built from labeled examples rather than hand-written rules.

Check yourself

  1. What is the key difference between traditional programming and machine learning?

    Show answer

    B. In ML the computer learns the rules from examples with answers, instead of a person writing them Traditional programming is rules plus data giving answers. ML is data plus answers giving the rules, which we call the model.

  2. Your music app suggests a song you have never heard, using a model trained last week. What is happening right now?

    Show answer

    C. Inference Applying an already-trained model to new data is inference. Training happened earlier, last week.

  3. For a model that predicts house prices, which of these is the label?

    Show answer

    C. The price the house actually sold for The label is the answer you want the model to predict. Floor area, bedrooms and neighbourhood are features, the inputs.

  4. A chess program searches moves using rules written by grandmasters and never learns. Which is true?

    Show answer

    C. It is AI but not machine learning AI is the broad goal of acting intelligently by any method. Without learning from data it is not machine learning.

Recap

  • Machine learning flips programming: you give examples with answers and the computer finds the rules, which become the model.
  • Features are the inputs, the label is the right answer, training fits the model, inference uses it on new data.
  • Deep learning sits inside machine learning, which sits inside AI.
  • Use ML when the pattern is too fuzzy to write by hand and you have plenty of labeled examples.

Get new lessons by email

Get new posts on backend and AI internals. No spam, unsubscribe anytime.

Your email is only used to send new posts. Privacy

Next up