1
Let’s Discuss Learning
1.1 Welcome
From time to time, people trot out a tired claim that computers can “only do what they
are told to do.” The claim is taken to mean that computers can only do what their
programmers know how to do and can explain to the computer. This claim is false.
Computers can perform tasks that their programmers cannot explain to them. Computers
can solve tasks that their programmers do not understand. We will break down this
paradox with an example of a computer program that learns.
I’ll start by discussing one of the oldest — if not the oldest known — examples of a
programmed machine-learning system. I’ve turned this into a story, but it is rooted in
historical facts. Arthur Samuel was working for IBM in the 1950s and he had an interesting
problem. He had to test the big computing machines that were coming o昀昀 the assembly
line to make sure transistors didn’t blow up when you turned a machine on and ran a
program — people don’t like smoke in their workplace. Now, Samuel quickly got bored
with running simple toy programs and, like many computing enthusiasts, he turned his
attention towards games. He built a computer program that let him play checkers against
himself. That was fun for a while: he tested IBM’s computers by playing checkers. But, as
is often the case, he got bored playing two-person games solo. His mind began to consider
the possibility of getting a good game of checkers against a computer opponent. Problem was,
he wasn’t good enough at checkers to explain good checkers strategies to a computer!
Samuel came up with the idea of having the computer learn how to play checkers. He
set up scenarios where the computer could make moves and evaluate the costs and bene昀椀ts
of those moves. At 昀椀rst, the computer was bad, very bad. But eventually, the program
started making progress. It was slow going. Suddenly, Samuel had a great two-for-one idea:
he decided to let one computer play another and take himself out of the loop. Because the
computers could make moves much faster than Samuel could enter his moves — let alone
think about them— the result was many more cycles of “make a move and evaluate the
outcome” per minute and hour and day.
Here is the amazing part. It didn’t take very long for the computer opponent to be
able to consistently beat Samuel. The computer became a better checkers player than its
programmer! How on earth could this happen, if “computers can only do what they are told
to do”? The answer to this riddle comes when we analyze what the computer was told to
Humble Bundle Pearson AI Bundle Ñ © Pearson. Do Not Distribute.
4 Chapter 1 Let’s Discuss Learning
do. What Samuel told the computer to do was not the play-checkers task; it was the
learn-to-play-checkers task. Yes, we just went all meta on you. Meta is what happens when
you take a picture of someone taking a picture (of someone else). Meta is what happens
when a sentence refers to itself; the next sentence is an example. This sentence has 昀椀ve
words. When we access the meta level, we step outside the box we were playing in and we
get an entirely new perspective on the world. Learning to play checkers — a task that develops
skill at another task— is a meta task. It lets us move beyond a limiting interpretation of
the statement, computers can only do what they are told. Computers do what they are told, but
they can be told to develop a capability. Computers can be told to learn.
1.2 Scope, Terminology, Prediction,
and Data
There are many kinds of computational learning systems out there. The academic 昀椀eld
that studies these systems is called machine learning. Our journey will focus on the current
wunderkind of learning systems that has risen to great prominence: learning from examples.
Even more speci昀椀cally, we will mostly be concerned with supervised learning from examples.
What is that? Here’s an example. I start by giving you several photos of two animals you’ve
never seen before— with apologies to Dr. Seuss, they might be a Lorax or a Who— and
then I tell you which animal is in which photo. If I give you a new, unseen photo you
might be able to tell me the type of animal in it. Congratulations, you’re doing great! You
just performed supervised learning from examples. When a computer is coaxed to learn
from examples, the examples are presented a certain way. Each example is measured
on a common group of attributes and we record the values for each attribute on each
example. Huh?
Imagine— or glance at Figure 1.1— a cartoon character running around with a
basket of di昀昀erent measuring sticks which, when held up to an object, return some
characteristic of that object, such as this vehicle has four wheels, this person has brown hair, the
temperature of that tea is 180◦ F, and so on ad nauseam (that’s an archaic way of saying until
you’re sick of my examples).
Figure 1.1 Humans have an insatiable desire to measure all sorts of things.
Humble Bundle Pearson AI Bundle Ñ © Pearson. Do Not Distribute.
1.2 Scope, Terminology, Prediction, and Data 5
1.2.1 Features
Let’s get a bit more concrete. For example — a meta-example, if you will — a dataset
focused on human medical records might record several relevant values for each patient,
such as height, weight, sex, age, smoking history, systolic and diastolic (that’s the high and
low numbers) blood pressures, and resting heart rate. The di昀昀erent people represented in
the dataset are our examples. The biometric and demographic characteristics are our
attributes.
We can capture this data very conveniently as in Table 1.1.
Table 1.1 A simple biomedical data table. Each row is an example. Each column
contains values for a given attribute. Together, each attribute-value pair is a feature of an
example.
patient id height weight sex age smoker hr sys bp dia bp
007 5’2” 120 M 11 no 75 120 80
2139 5’4” 140 F 41 no 65 115 75
1111 5’11” 185 M 41 no 52 125 75
Notice that each example — each row — is measured on the same attributes shown in
the header row. The values of each attribute run down the respective columns.
We call the rows of the table the examples of the dataset and we refer to the columns as
the features. Features are the measurements or values of our attributes. Often, people use
“features” and “attributes” as synonyms describing the same thing; what they are referring
to are the column of values. Still, some people like to distinguish among three concepts:
what-is-measured, what-the-value-is, and what-the-measured-value-is. For those strict folks, the
昀椀rst is an attribute, the second is a value, and the last is a feature— an attribute and a value
paired together. Again, we’ll mostly follow the typical conversational usage and call the
columns features. If we are speci昀椀cally talking about what-is-measured, we’ll stick with the
term attribute. You will inevitably see both, used both ways, when you read about machine
learning.
Let’s take a moment and look at the types of values our attributes — what is
measured— can take. One type of value distinguishes between di昀昀erent groups of people.
We might see such groups in a census or an epidemiological medical study — for
example, sex {male, female} or a broad record of ethnic-cultural-genetic heritage
{African, Asian, European, Native American, Polynesian}. Attributes like these are called
discrete, symbolic, categorical, or nominal attributes, but we are not going to stress about
those names. If you struggled with those in a social science class, you are free to give a
hearty huzzah.
Here are two important, or at least practical, points about categorical data. One point
is that these values are discrete. They take a small, limited number of possibilities that
typically represent one of several options. You’re right that small and several are relative
terms — just go with it. The second point is that the information in those attributes can be
recorded in two distinct ways:
Humble Bundle Pearson AI Bundle Ñ © Pearson. Do Not Distribute.
6 Chapter 1 Let’s Discuss Learning
. As a single feature that takes one value for each option, or
. As several features, one per option, where one, and only one, of those features is
marked as yes or true and the remainder are marked as no or false.
Here’s an example. Consider
Name Sex
Mark Male
Barb Female
Ethan Male
versus:
Name Sex is Female Sex is Male
Mark No Yes
Barb Yes No
Ethan No Yes
If we had a column for community type in a census, the values might be Urban, Rural,
and Suburban with three possible values. If we had the expanded, multicolumn form, it
would take up three columns. Generally, we aren’t motivated or worried about table size
here. What matters is that some learning methods are, shall we say, particular in preferring
one form or the other. There are other details to point out, but we’ll save them for later.
Some feature values can be recorded and operated on as numbers. We may lump them
together under the term numerical features. In other contexts, they are known as continuous
or, depending on other details, interval or ratio values. Values for attributes like height and
weight are typically recorded as decimal numbers. Values for attributes like age and blood
pressure are often recorded as whole numbers. Values like counts— say, how many wheels
are on a vehicle— are strictly whole numbers. Conveniently, we can perform arithmetic
(+, −, ×, / ) on these. While we can record categorical data as numbers, we can’t
necessarily perform meaningful numerical calculations directly on those values. If two
states — say, Pennsylvania and Vermont— are coded as 2 and 14, it probably makes no
sense to perform arithmetic on those values. There is an exception: if, by design, those
values mean something beyond a unique identi昀椀er, we might be able to do some or all of
the maths. For extra credit, you can 昀椀nd some meaning in the state values I used where
mathematics would make sense.
1.2.2 Target Values and Predictions
Let’s shift our focus back to the list of biomedical attributes we gathered. As a reminder,
the column headings were height, weight, sex, age, smoker, heart rate, systolic blood
pressure, and diastolic blood pressure. These attributes might be useful data for a health
care provider trying to assess the likelihood of a patient developing cardiovascular heart. To
do so, we would need another piece of information: did these folks develop heart disease?
Humble Bundle Pearson AI Bundle Ñ © Pearson. Do Not Distribute.
1.3 Putting the Machine in Machine Learning 7
If we have that information, we can add it to the list of attributes. We could capture and
record the idea of “developing heart disease” in several di昀昀erent ways. Did the patient:
. Develop any heart disease within ten years: yes/no
. Develop X-level severity heart disease within ten years: None or Grade I, II, III
. Show some level of a speci昀椀c indicator for heart disease within ten years: percent of
coronary artery blockage
We could tinker with these questions based on resources at our disposal, medically
relevant knowledge, and the medical or scienti昀椀c puzzles we want to solve. Time is a
precious resource; we might not have ten years to wait for an outcome. There might be
medical knowledge about what percent of blockage is a critical amount. We could modify
the time horizon or come up with di昀昀erent attributes to record.
In any case, we can pick a concrete, measurable target and ask, “Can we 昀椀nd a
predictive relationship between the attributes we have today and the outcome that we will
see at some future time?” We are literally trying to predict the future— maybe ten years from
now — from things we know today. We call the concrete outcome our target feature or
simply our target. If our target is a category like {sick, healthy} or {None, I, II, III}, we call
the process of learning the relationship classi昀椀cation. Here, we are using the term
classi昀椀cation in the sense of 昀椀nding the di昀昀erent classes, or categories, of a possible
outcome. If the target is a smooth sweeping of numerical values, like the usual decimal
numbers from elementary school {27.2, 42.0, 3.14159, −117.6}, we call the process
regression. If you want to know why, go and google Galton regression for the history lesson.
We now have some handy terminology in our toolbox: most importantly features, both
either categorical or numerical, and a target. If we want to emphasize the features being used
to predict the future unknown outcome, we may call them input features or predictive
features. There are a few issues I’ve swept under the carpet. In particular, we’ll address some
alternative terminology at the end of the chapter.
1.3 Putting the Machine in Machine
Learning
I want you to create a mental image of a factory machine. If you need help, glance at
Figure 1.2. On the left-hand side, there is a conveyor belt that feeds inputs into the
machine. On the right-hand side, the machine spits out outputs which are words or
numbers. The words might be cat or dog. The numbers might be {0, 1} or {−2.1, 3.7}.
The machine itself is a big hulking box of metal. We can’t really see what happens on the
inside. But we can see a control panel on the side of the machine, with an operator’s seat in
front of it. The control panel has some knobs we can set to numerical values and some
switches we can 昀氀ip on and o昀昀. By adjusting the knobs and switches, we can make
di昀昀erent products appear on the right-hand side of the machine, depending on what came
in the left-hand side. Lastly, there is a small side tray beside the operator’s chair. The tray
can be used to feed additional information, that is not easily captured by knobs and
switches, into the machine. Two quick notes for the skeptical reader: our knobs can get us
Humble Bundle Pearson AI Bundle Ñ © Pearson. Do Not Distribute.