← All courses

Course 2 · Machine Learning Basics · about 15 min

Rules in, or rules out?

By the end of this course you can tell the main types of machine learning apart, explain why models overfit, and pick a sensible first algorithm.

A friendly robot measuring an apple with a ruler and weighing an orange on a kitchen scale
Illustration made with olalilu.com
Traditional programmingA person writes the rules. The computer applies them to data and produces answers.
Machine learningA person supplies data and the answers. The computer works out the rules. Those learned rules are called a model.

Machine learning pays off when the rules are too messy to write by hand. Nobody can write a rule for "what a cat looks like", but a model can learn it from thousands of labelled photos.

Try itYou are the algorithm

Here are six labelled examples. Study them, then label the three new fruits.

WeightSkinLabel
150 gsmoothApple
180 gsmoothApple
140 gsmoothApple
170 gbumpyOrange
230 gbumpyOrange
190 gbumpyOrange

You just learned from labelled examples. That is exactly what a machine learning model does, only with millions of examples and many more features.

CheckIn machine learning, what does the computer produce?

Step 2

Learning with and without answers

Supervised learning uses labelled data: every example comes with the right answer. It handles two kinds of task:

Unsupervised learning gets data with no answers. It looks for structure on its own. The most common task is clustering: grouping similar things together, like customers who shop in similar ways.

Try itWhich task is it?

CheckYou have customer data with no labels and want to find natural groups. Which type of learning is that?

Step 3

From data to a working model

Every machine learning project follows roughly the same workflow. One step matters more than beginners expect: you hide part of your data from the model while it trains. That hidden part is the test set.

Think of an exam. If students saw the exact questions in advance, a perfect score proves nothing. The test set gives the model questions it has never seen, so its score tells you how it will do in the real world.

Try itPut the workflow in order

Tap the first step, then the next one.

CheckWhy keep a test set that the model never trains on?

Step 4

Too simple, too clever

A model can fail in two opposite ways:

Think of two students facing new exam questions. One memorised last year's answers and is lost. The other learned the ideas behind them and can work out anything new. You want your model to be the second student.

Two students at desks: one sorting through a pile of flashcards, the other calmly sketching a diagram
Illustration made with olalilu.com

Try itFind the sweet spot

Turn up the model's complexity and watch both scores. Which level would you ship?

1
Training data
New data

Leo Breiman, a Berkeley statistician, introduced random forests in 2001. Instead of one very flexible model, they combine many simple decision trees, which makes overfitting much less likely.

CheckA model scores 99% on training data and 70% on new data. What is going on?

Step 5

Your first algorithms

There are hundreds of algorithms, but three cover most beginner projects:

Start simple. A simple model is quick to train, easy to explain, and gives you a baseline that any fancier model has to beat.

Try itPick the algorithm

Andrew Ng, who co-founded Google Brain and Coursera, taught machine learning to millions online. His standing advice: get a simple version working quickly, then improve it based on where it fails.

CheckWhy start with a simple algorithm?

Step 6 · Recap

What you learned

Quick reviewThree questions from memory. No scrolling back.

Want to try this for real? scikit-learn, a free Python library, has all three algorithms from this course built in. When you're ready, mark the course complete below.