Machine learningLoading progress…

Learning settings

Define a learning problem, establish a baseline and evaluate it on data not used for fitting.

What kind of data do you have?

"Machine learning" covers several problem types. The cleanest way to tell them apart is to ask what data comes with the problem.

  • Supervised learning: every example has inputs and the correct answer. The model learns to map inputs to answers. Predicting a number is called regression, predicting a category is classification.
  • Unsupervised learning: only inputs, no answers. The model looks for structure, such as groups of similar customers (clustering) or unusual cases (anomaly detection).
  • Reinforcement learning: a learner takes actions and receives rewards. Nobody supplies the correct action, and the actions change what the learner sees next.

0 of 6 scenarios correct.

Predict a house price from 5,000 past sales, each with its recorded sale price.

Setting:
Data the learner needs:

Split 20,000 customers into groups of similar shoppers. Nobody has defined the groups in advance.

Setting:
Data the learner needs:

Sort email into spam and not spam, using mail that users already marked as spam.

Setting:
Data the learner needs:

A simulated robot tries to walk. It is scored by how far it moves, and each step changes what it sees next.

Setting:
Data the learner needs:

Find unusual card transactions in a pile of transactions that carry no fraud labels.

Setting:
Data the learner needs:

Pick which of three ads to show to each visitor. Only the shown ad earns a click or no click, and what you learn depends on what you chose to show.

Setting:
Data the learner needs:
Sort six scenarios. For each one pick the setting and tick exactly the data it needs.

Same table, different question

The setting is decided by the question, not the table. Take the housing data with the price column. Predicting price from the other columns is supervised. Delete the price column and ask "which houses are similar?" and it becomes unsupervised. Neither one is reinforcement learning, because nothing is acting and being rewarded.

Predict first. You have 10,000 news articles with no topic labels, and you want to sort them into groups of similar articles. Which setting?

Common mistake: calling everything supervised

This course follows mostly the supervised setting first, because it is the easiest to measure: you can compare predictions with the known answers.

Chapter context

A learning algorithm chooses a model from data rather than requiring a person to specify every decision rule. The resulting model is useful only if its predictions transfer to the intended future inputs under a clearly defined objective.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

For labeled data D={(xi,yi)}i=1nD=\{(x_i,y_i)\}_{i=1}^n, empirical risk is

R^(θ)=1n∑iℓ(fθ(xi),yi).\hat R(\theta)=\frac1n\sum_i\ell(f_\theta(x_i),y_i).

It estimates performance on the sampled population, not automatically on every deployment population. Accuracy is the fraction of correct predictions when classification is the task.

Worked example

A classifier predicts five held-out labels: [1,0,1,1,0] for actual labels [1,0,0,1,0]. Four are correct, so accuracy is 4/5=0.8. This number says nothing about its training accuracy or behavior on a differently collected test set.

Reference code

The following example uses the Python standard library and does not call a remote service.

actual = [1,0,0,1,0]
predicted = [1,0,1,1,0]
correct = sum(a == b for a,b in zip(actual,predicted))
assert correct == 4
assert correct/len(actual) == .8

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

Learning a pattern does not establish causation. Validation data used repeatedly for model selection is no longer an untouched test. A random split is not always an independent split.