lesson
30 min

How Machines Learn From Data

Rules versus learned patterns, the steps of a machine learning project, and the first judgment call.

Objective

By the end of this lesson, you can explain the difference between a rule and a learned pattern, and list the steps of a machine learning project.

Rules versus patterns

There are two ways to make a computer decide something.

Rules. A person writes the logic. "If the temperature is below 32 degrees Fahrenheit, warn about ice." Rules are clear and easy to check.

Learned patterns. You give the computer many examples with answers. It finds the pattern on its own. This is machine learning: software that improves at a task by studying examples instead of following hand-written rules.

Here is a simple rule in Python. You can run it on this page. The first run downloads Python into your browser. That takes a moment and uses some data, so the code is also shown below for reading.

temperature_f = 28
if temperature_f < 32:
    print("Ice warning")
else:
    print("No ice warning")
Run the rule. Then change temperature_f to 40 and run it again. A rule like this needs no machine learning at all.
Python 3
Ctrl+Enter to run | Tab to indent | Python runs in your browser via Pyodide

When a rule is better

Use a rule when the logic is known, stable, and easy to explain. Water freezes at 32 degrees. You do not need a model to learn that.

Use machine learning when the pattern is real but too messy to write down. How much power a region uses tomorrow depends on weather, the day of the week, holidays, and more. That is a good fit for a model.

Judgment check: if a simple rule works, use the rule. It is easier to explain, test, and fix.

The steps of a project

Every project in this course follows the same path:

  1. Question. What decision will this help with? Who makes it?
  2. Data. Where does it come from? Who is in it, and who is missing?
  3. Prepare. Clean it, fix gaps, and shape it into a table.
  4. Explore. Chart it. Look before you model.
  5. Model. Train on part of the data.
  6. Test. Check on data the model has never seen.
  7. Review. Who is affected if it is wrong? Is it fair? Should it ship?

A national example

Quiz: Rule or model?

  1. 01A library wants to send a reminder when a book is 3 days overdue. What fits best?

    Choose one.

  2. 02Which step comes right before training a model?

    Choose one.

  3. 03Why do we test on data the model has never seen?

    Choose one.

Go deeper: Machine Learning, Minus the Hype: A Practical Playbook to Ship Useful Models

Ask. Answer. Build together.