Learning settings
Define a learning problem, establish a baseline and evaluate it on data not used for fitting.
THE IDEA
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.
Split 20,000 customers into groups of similar shoppers. Nobody has defined the groups in advance.
Sort email into spam and not spam, using mail that users already marked as spam.
A simulated robot tries to walk. It is scored by how far it moves, and each step changes what it sees next.
Find unusual card transactions in a pile of transactions that carry no fraud labels.
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.
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.
TRY IT YOURSELF
Six scenarios. A scenario counts as correct only when both the setting and the exact set of data it needs are right.
0 of 6 scenarios correct.
Predict a house price from 5,000 past sales, each with its recorded sale price.
Split 20,000 customers into groups of similar shoppers. Nobody has defined the groups in advance.
Sort email into spam and not spam, using mail that users already marked as spam.
A simulated robot tries to walk. It is scored by how far it moves, and each step changes what it sees next.
Find unusual card transactions in a pile of transactions that carry no fraud labels.
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.
- To do: Get the three supervised scenarios right (setting plus the data it needs)
- To do: Get both unsupervised scenarios right
- To do: Get both reinforcement scenarios right
- To do: All six scenarios correct
Stuck, or something not working? You can come back to it any time.
CHECK YOUR UNDERSTANDING
Is grouping unlabeled documents the same task as predicting their supplied topic labels?
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 , empirical risk is
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.