master
pdf
keyboard_arrow_up
School
University of Cincinnati, Main Campus *
*We aren’t endorsed by this school
Course
OPTIMIZATI
Subject
Computer Science
Date
Oct 30, 2023
Type
Pages
135
Uploaded by BrigadierGorillaMaster2190
CS229 Lecture Notes
Andrew Ng
Updated by Tengyu Ma
Contents
I
Supervised learning
4
1
Linear regression
7
1.1
LMS algorithm
. . . . . . . . . . . . . . . . . . . . . . . . . .
8
1.2
The normal equations
. . . . . . . . . . . . . . . . . . . . . . .
12
1.2.1
Matrix derivatives
. . . . . . . . . . . . . . . . . . . . .
12
1.2.2
Least squares revisited
. . . . . . . . . . . . . . . . . .
13
1.3
Probabilistic interpretation
. . . . . . . . . . . . . . . . . . . .
14
1.4
Locally weighted linear regression (optional reading)
. . . . . .
16
2
Classification and logistic regression
19
2.1
Logistic regression
. . . . . . . . . . . . . . . . . . . . . . . .
19
2.2
Digression: the perceptron learning algorithn
. . . . . . . . . .
22
2.3
Another algorithm for maximizing
‘
(
θ
)
. . . . . . . . . . . . .
23
3
Generalized linear models
25
3.1
The exponential family
. . . . . . . . . . . . . . . . . . . . . .
25
3.2
Constructing GLMs
. . . . . . . . . . . . . . . . . . . . . . . .
27
3.2.1
Ordinary least squares
. . . . . . . . . . . . . . . . . .
28
3.2.2
Logistic regression
. . . . . . . . . . . . . . . . . . . .
29
3.2.3
Softmax regression
. . . . . . . . . . . . . . . . . . . .
29
4
Generative learning algorithms
34
4.1
Gaussian discriminant analysis
. . . . . . . . . . . . . . . . . .
35
4.1.1
The multivariate normal distribution
. . . . . . . . . .
35
4.1.2
The Gaussian discriminant analysis model
. . . . . . .
38
4.1.3
Discussion: GDA and logistic regression
. . . . . . . .
40
4.2
Naive bayes
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
4.2.1
Laplace smoothing
. . . . . . . . . . . . . . . . . . . .
44
4.2.2
Event models for text classification (optional reading) .
46
1
CS229 Spring 2022
2
5
Kernel methods
48
5.1
Feature maps
. . . . . . . . . . . . . . . . . . . . . . . . . . .
48
5.2
LMS (least mean squares) with features
. . . . . . . . . . . . .
49
5.3
LMS with the kernel trick
. . . . . . . . . . . . . . . . . . . .
49
5.4
Properties of kernels
. . . . . . . . . . . . . . . . . . . . . . .
53
6
Support vector machines
59
6.1
Margins: intuition
. . . . . . . . . . . . . . . . . . . . . . . . .
59
6.2
Notation (option reading)
. . . . . . . . . . . . . . . . . . . .
61
6.3
Functional and geometric margins (option reading)
. . . . . .
61
6.4
The optimal margin classifier (option reading)
. . . . . . . . .
63
6.5
Lagrange duality (optional reading)
. . . . . . . . . . . . . . .
65
6.6
Optimal margin classifiers: the dual form (option reading)
. .
68
6.7
Regularization and the non-separable case (optional reading) .
72
6.8
The SMO algorithm (optional reading)
. . . . . . . . . . . . .
73
6.8.1
Coordinate ascent
. . . . . . . . . . . . . . . . . . . . .
74
6.8.2
SMO
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
75
II
Deep learning
79
7
Deep learning
80
7.1
Supervised learning with non-linear models
. . . . . . . . . . .
80
7.2
Neural networks
. . . . . . . . . . . . . . . . . . . . . . . . . .
82
7.3
Backpropagation
. . . . . . . . . . . . . . . . . . . . . . . . .
91
7.3.1
Preliminary: chain rule
. . . . . . . . . . . . . . . . . .
92
7.3.2
One-neuron neural networks
. . . . . . . . . . . . . . .
92
7.3.3
Two-layer neural networks: a low-level unpacked com-
putation
. . . . . . . . . . . . . . . . . . . . . . . . . .
93
7.3.4
Two-layer neural network with vector notation
. . . . .
96
7.3.5
Multi-layer neural networks
. . . . . . . . . . . . . . .
98
7.4
Vectorization over training examples
. . . . . . . . . . . . . .
98
III
Generalization and regularization
101
8
Generalization
102
8.1
Bias-variance tradeoff
. . . . . . . . . . . . . . . . . . . . . . .
104
8.1.1
A mathematical decomposition (for regression)
. . . . .
109
8.2
The double descent phenomenon
. . . . . . . . . . . . . . . . .
110
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
CS229 Spring 2022
3
8.3
Sample complexity bounds (optional readings)
. . . . . . . . .
115
8.3.1
Preliminaries
. . . . . . . . . . . . . . . . . . . . . . .
115
8.3.2
The case of finite
H
. . . . . . . . . . . . . . . . . . . .
117
8.3.3
The case of infinite
H
. . . . . . . . . . . . . . . . . .
120
9
Regularization and model selection
124
9.1
Regularization
. . . . . . . . . . . . . . . . . . . . . . . . . . .
124
9.2
Implicit regularization effect
. . . . . . . . . . . . . . . . . . .
126
9.3
Model selection via cross validation
. . . . . . . . . . . . . . .
128
9.4
Bayesian statistics and regularization
. . . . . . . . . . . . . .
131
Part I
Supervised learning
4
5
Let’s start by talking about a few examples of supervised learning prob-
lems.
Suppose we have a dataset giving the living areas and prices of 47
houses from Portland, Oregon:
Living area (feet
2
)
Price (1000
$
s)
2104
400
1600
330
2400
369
1416
232
3000
540
.
.
.
.
.
.
We can plot this data:
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
0
100
200
300
400
500
600
700
800
900
1000
housing prices
square feet
price (in $1000)
Given data like this, how can we learn to predict the prices of other houses
in Portland, as a function of the size of their living areas?
To establish notation for future use, we’ll use
x
(
i
)
to denote the “input”
variables (living area in this example), also called input
features
, and
y
(
i
)
to denote the “output” or
target
variable that we are trying to predict
(price).
A pair (
x
(
i
)
, y
(
i
)
) is called a
training example
, and the dataset
that we’ll be using to learn—a list of
n
training examples
{
(
x
(
i
)
, y
(
i
)
);
i
=
1
, . . . , n
}
—is called a
training set
. Note that the superscript “(
i
)” in the
notation is simply an index into the training set, and has nothing to do with
exponentiation. We will also use
X
denote the space of input values, and
Y
the space of output values. In this example,
X
=
Y
=
R
.
To describe the supervised learning problem slightly more formally, our
goal is, given a training set, to learn a function
h
:
X 7→ Y
so that
h
(
x
) is a
“good” predictor for the corresponding value of
y
. For historical reasons, this
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
6
function
h
is called a
hypothesis
. Seen pictorially, the process is therefore
like this:
Training set
house.)
(living area of
Learning algorithm
h
predicted y
x
(predicted price)
of house)
When the target variable that we’re trying to predict is continuous, such
as in our housing example, we call the learning problem a
regression
prob-
lem. When
y
can take on only a small number of discrete values (such as
if, given the living area, we wanted to predict if a dwelling is a house or an
apartment, say), we call it a
classification
problem.
Chapter 1
Linear regression
To make our housing example more interesting, let’s consider a slightly richer
dataset in which we also know the number of bedrooms in each house:
Living area (feet
2
)
#bedrooms
Price (1000
$
s)
2104
3
400
1600
3
330
2400
3
369
1416
2
232
3000
4
540
.
.
.
.
.
.
.
.
.
Here, the
x
’s are two-dimensional vectors in
R
2
. For instance,
x
(
i
)
1
is the
living area of the
i
-th house in the training set, and
x
(
i
)
2
is its number of
bedrooms. (In general, when designing a learning problem, it will be up to
you to decide what features to choose, so if you are out in Portland gathering
housing data, you might also decide to include other features such as whether
each house has a fireplace, the number of bathrooms, and so on. We’ll say
more about feature selection later, but for now let’s take the features as
given.)
To perform supervised learning, we must decide how we’re going to rep-
resent functions/hypotheses
h
in a computer. As an initial choice, let’s say
we decide to approximate
y
as a linear function of
x
:
h
θ
(
x
) =
θ
0
+
θ
1
x
1
+
θ
2
x
2
Here, the
θ
i
’s are the
parameters
(also called
weights
) parameterizing the
space of linear functions mapping from
X
to
Y
.
When there is no risk of
7
8
confusion, we will drop the
θ
subscript in
h
θ
(
x
), and write it more simply as
h
(
x
). To simplify our notation, we also introduce the convention of letting
x
0
= 1 (this is the
intercept term
), so that
h
(
x
) =
d
X
i
=0
θ
i
x
i
=
θ
T
x,
where on the right-hand side above we are viewing
θ
and
x
both as vectors,
and here
d
is the number of input variables (not counting
x
0
).
Now, given a training set, how do we pick, or learn, the parameters
θ
?
One reasonable method seems to be to make
h
(
x
) close to
y
, at least for
the training examples we have. To formalize this, we will define a function
that measures, for each value of the
θ
’s, how close the
h
(
x
(
i
)
)’s are to the
corresponding
y
(
i
)
’s. We define the
cost function
:
J
(
θ
) =
1
2
n
X
i
=1
(
h
θ
(
x
(
i
)
)
-
y
(
i
)
)
2
.
If you’ve seen linear regression before, you may recognize this as the familiar
least-squares cost function that gives rise to the
ordinary least squares
regression model.
Whether or not you have seen it previously, let’s keep
going, and we’ll eventually show this to be a special case of a much broader
family of algorithms.
1.1
LMS algorithm
We want to choose
θ
so as to minimize
J
(
θ
).
To do so, let’s use a search
algorithm that starts with some “initial guess” for
θ
, and that repeatedly
changes
θ
to make
J
(
θ
) smaller, until hopefully we converge to a value of
θ
that minimizes
J
(
θ
).
Specifically, let’s consider the
gradient descent
algorithm, which starts with some initial
θ
, and repeatedly performs the
update:
θ
j
:=
θ
j
-
α
∂
∂θ
j
J
(
θ
)
.
(This update is simultaneously performed for all values of
j
= 0
, . . . , d
.)
Here,
α
is called the
learning rate
. This is a very natural algorithm that
repeatedly takes a step in the direction of steepest decrease of
J
.
In order to implement this algorithm, we have to work out what is the
partial derivative term on the right hand side. Let’s first work it out for the
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
9
case of if we have only one training example (
x, y
), so that we can neglect
the sum in the definition of
J
. We have:
∂
∂θ
j
J
(
θ
)
=
∂
∂θ
j
1
2
(
h
θ
(
x
)
-
y
)
2
=
2
·
1
2
(
h
θ
(
x
)
-
y
)
·
∂
∂θ
j
(
h
θ
(
x
)
-
y
)
=
(
h
θ
(
x
)
-
y
)
·
∂
∂θ
j
d
X
i
=0
θ
i
x
i
-
y
!
=
(
h
θ
(
x
)
-
y
)
x
j
For a single training example, this gives the update rule:
1
θ
j
:=
θ
j
+
α
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
j
.
The rule is called the
LMS
update rule (LMS stands for “least mean squares”),
and is also known as the
Widrow-Hoff
learning rule. This rule has several
properties that seem natural and intuitive. For instance, the magnitude of
the update is proportional to the
error
term (
y
(
i
)
-
h
θ
(
x
(
i
)
)); thus, for in-
stance, if we are encountering a training example on which our prediction
nearly matches the actual value of
y
(
i
)
, then we find that there is little need
to change the parameters; in contrast, a larger change to the parameters will
be made if our prediction
h
θ
(
x
(
i
)
) has a large error (i.e., if it is very far from
y
(
i
)
).
We’d derived the LMS rule for when there was only a single training
example.
There are two ways to modify this method for a training set of
more than one example. The first is replace it with the following algorithm:
Repeat until convergence
{
θ
j
:=
θ
j
+
α
n
X
i
=1
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
j
,
(for every
j
)
(1.1)
}
1
We use the notation “
a
:=
b
” to denote an operation (in a computer program) in
which we
set
the value of a variable
a
to be equal to the value of
b
. In other words, this
operation overwrites
a
with the value of
b
. In contrast, we will write “
a
=
b
” when we are
asserting a statement of fact, that the value of
a
is equal to the value of
b
.
10
By grouping the updates of the coordinates into an update of the vector
θ
, we can rewrite update (1.1) in a slightly more succinct way:
θ
:=
θ
+
α
n
X
i
=1
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
The reader can easily verify that the quantity in the summation in the
update rule above is just
∂J
(
θ
)
/∂θ
j
(for the original definition of
J
). So, this
is simply gradient descent on the original cost function
J
. This method looks
at every example in the entire training set on every step, and is called
batch
gradient descent
.
Note that, while gradient descent can be susceptible
to local minima in general, the optimization problem we have posed here
for linear regression has only one global, and no other local, optima; thus
gradient descent always converges (assuming the learning rate
α
is not too
large) to the global minimum.
Indeed,
J
is a convex quadratic function.
Here is an example of gradient descent as it is run to minimize a quadratic
function.
5
10
15
20
25
30
35
40
45
50
5
10
15
20
25
30
35
40
45
50
The ellipses shown above are the contours of a quadratic function.
Also
shown is the trajectory taken by gradient descent, which was initialized at
(48,30). The
x
’s in the figure (joined by straight lines) mark the successive
values of
θ
that gradient descent went through.
When we run batch gradient descent to fit
θ
on our previous dataset,
to learn to predict housing price as a function of living area, we obtain
θ
0
= 71
.
27,
θ
1
= 0
.
1345.
If we plot
h
θ
(
x
) as a function of
x
(area), along
with the training data, we obtain the following figure:
11
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
0
100
200
300
400
500
600
700
800
900
1000
housing prices
square feet
price (in $1000)
If the number of bedrooms were included as one of the input features as well,
we get
θ
0
= 89
.
60
, θ
1
= 0
.
1392,
θ
2
=
-
8
.
738.
The above results were obtained with batch gradient descent. There is
an alternative to batch gradient descent that also works very well. Consider
the following algorithm:
Loop
{
for
i
= 1 to
n
,
{
θ
j
:=
θ
j
+
α
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
j
,
(for every
j
)
(1.2)
}
}
By grouping the updates of the coordinates into an update of the vector
θ
, we can rewrite update (1.2) in a slightly more succinct way:
θ
:=
θ
+
α
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
In this algorithm, we repeatedly run through the training set, and each
time we encounter a training example, we update the parameters according
to the gradient of the error with respect to that single training example only.
This algorithm is called
stochastic gradient descent
(also
incremental
gradient descent
).
Whereas batch gradient descent has to scan through
the entire training set before taking a single step—a costly operation if
n
is
large—stochastic gradient descent can start making progress right away, and
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
12
continues to make progress with each example it looks at. Often, stochastic
gradient descent gets
θ
“close” to the minimum much faster than batch gra-
dient descent. (Note however that it may never “converge” to the minimum,
and the parameters
θ
will keep oscillating around the minimum of
J
(
θ
); but
in practice most of the values near the minimum will be reasonably good
approximations to the true minimum.
2
) For these reasons, particularly when
the training set is large, stochastic gradient descent is often preferred over
batch gradient descent.
1.2
The normal equations
Gradient descent gives one way of minimizing
J
. Let’s discuss a second way
of doing so, this time performing the minimization explicitly and without
resorting to an iterative algorithm. In this method, we will minimize
J
by
explicitly taking its derivatives with respect to the
θ
j
’s, and setting them to
zero. To enable us to do this without having to write reams of algebra and
pages full of matrices of derivatives, let’s introduce some notation for doing
calculus with matrices.
1.2.1
Matrix derivatives
For a function
f
:
R
n
×
d
7→
R
mapping from
n
-by-
d
matrices to the real
numbers, we define the derivative of
f
with respect to
A
to be:
∇
A
f
(
A
) =
∂f
∂A
11
· · ·
∂f
∂A
1
d
.
.
.
.
.
.
.
.
.
∂f
∂A
n
1
· · ·
∂f
∂A
nd
Thus, the gradient
∇
A
f
(
A
) is itself an
n
-by-
d
matrix, whose (
i, j
)-element is
∂f/∂A
ij
. For example, suppose
A
=
A
11
A
12
A
21
A
22
is a 2-by-2 matrix, and
the function
f
:
R
2
×
2
7→
R
is given by
f
(
A
) =
3
2
A
11
+ 5
A
2
12
+
A
21
A
22
.
2
By slowly letting the learning rate
α
decrease to zero as the algorithm runs, it is also
possible to ensure that the parameters will converge to the global minimum rather than
merely oscillate around the minimum.
13
Here,
A
ij
denotes the (
i, j
) entry of the matrix
A
. We then have
∇
A
f
(
A
) =
3
2
10
A
12
A
22
A
21
.
1.2.2
Least squares revisited
Armed with the tools of matrix derivatives, let us now proceed to find in
closed-form the value of
θ
that minimizes
J
(
θ
). We begin by re-writing
J
in
matrix-vectorial notation.
Given a training set, define the
design matrix
X
to be the
n
-by-
d
matrix
(actually
n
-by-
d
+ 1, if we include the intercept term) that contains the
training examples’ input values in its rows:
X
=
— (
x
(1)
)
T
—
— (
x
(2)
)
T
—
.
.
.
— (
x
(
n
)
)
T
—
.
Also, let
~
y
be the
n
-dimensional vector containing all the target values from
the training set:
~
y
=
y
(1)
y
(2)
.
.
.
y
(
n
)
.
Now, since
h
θ
(
x
(
i
)
) = (
x
(
i
)
)
T
θ
, we can easily verify that
Xθ
-
~
y
=
(
x
(1)
)
T
θ
.
.
.
(
x
(
n
)
)
T
θ
-
y
(1)
.
.
.
y
(
n
)
=
h
θ
(
x
(1)
)
-
y
(1)
.
.
.
h
θ
(
x
(
n
)
)
-
y
(
n
)
.
Thus, using the fact that for a vector
z
, we have that
z
T
z
=
∑
i
z
2
i
:
1
2
(
Xθ
-
~
y
)
T
(
Xθ
-
~
y
)
=
1
2
n
X
i
=1
(
h
θ
(
x
(
i
)
)
-
y
(
i
)
)
2
=
J
(
θ
)
14
Finally, to minimize
J
, let’s find its derivatives with respect to
θ
. Hence,
∇
θ
J
(
θ
)
=
∇
θ
1
2
(
Xθ
-
~
y
)
T
(
Xθ
-
~
y
)
=
1
2
∇
θ
(
(
Xθ
)
T
Xθ
-
(
Xθ
)
T
~
y
-
~
y
T
(
Xθ
) +
~
y
T
~
y
)
=
1
2
∇
θ
(
θ
T
(
X
T
X
)
θ
-
~
y
T
(
Xθ
)
-
~
y
T
(
Xθ
)
)
=
1
2
∇
θ
(
θ
T
(
X
T
X
)
θ
-
2(
X
T
~
y
)
T
θ
)
=
1
2
(
2
X
T
Xθ
-
2
X
T
~
y
)
=
X
T
Xθ
-
X
T
~
y
In the third step, we used the fact that
a
T
b
=
b
T
a
, and in the fifth step
used the facts
∇
x
b
T
x
=
b
and
∇
x
x
T
Ax
= 2
Ax
for symmetric matrix
A
(for
more details, see Section 4.3 of “Linear Algebra Review and Reference”). To
minimize
J
, we set its derivatives to zero, and obtain the
normal equations
:
X
T
Xθ
=
X
T
~
y
Thus, the value of
θ
that minimizes
J
(
θ
) is given in closed form by the
equation
θ
= (
X
T
X
)
-
1
X
T
~
y.
3
1.3
Probabilistic interpretation
When faced with a regression problem, why might linear regression, and
specifically why might the least-squares cost function
J
, be a reasonable
choice? In this section, we will give a set of probabilistic assumptions, under
which least-squares regression is derived as a very natural algorithm.
Let us assume that the target variables and the inputs are related via the
equation
y
(
i
)
=
θ
T
x
(
i
)
+
(
i
)
,
3
Note that in the above step, we are implicitly assuming that
X
T
X
is an invertible
matrix.
This can be checked before calculating the inverse.
If either the number of
linearly independent examples is fewer than the number of features, or if the features
are not linearly independent, then
X
T
X
will not be invertible. Even in such cases, it is
possible to “fix” the situation with additional techniques, which we skip here for the sake
of simplicty.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
15
where
(
i
)
is an error term that captures either unmodeled effects (such as
if there are some features very pertinent to predicting housing price, but
that we’d left out of the regression), or random noise. Let us further assume
that the
(
i
)
are distributed IID (independently and identically distributed)
according to a Gaussian distribution (also called a Normal distribution) with
mean zero and some variance
σ
2
. We can write this assumption as “
(
i
)
∼
N
(0
, σ
2
).” I.e., the density of
(
i
)
is given by
p
(
(
i
)
) =
1
√
2
πσ
exp
-
(
(
i
)
)
2
2
σ
2
.
This implies that
p
(
y
(
i
)
|
x
(
i
)
;
θ
) =
1
√
2
πσ
exp
-
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
2
σ
2
.
The notation “
p
(
y
(
i
)
|
x
(
i
)
;
θ
)” indicates that this is the distribution of
y
(
i
)
given
x
(
i
)
and parameterized by
θ
. Note that we should not condition on
θ
(“
p
(
y
(
i
)
|
x
(
i
)
, θ
)”), since
θ
is not a random variable.
We can also write the
distribution of
y
(
i
)
as
y
(
i
)
|
x
(
i
)
;
θ
∼ N
(
θ
T
x
(
i
)
, σ
2
).
Given
X
(the design matrix, which contains all the
x
(
i
)
’s) and
θ
, what
is the distribution of the
y
(
i
)
’s?
The probability of the data is given by
p
(
~
y
|
X
;
θ
). This quantity is typically viewed a function of
~
y
(and perhaps
X
),
for a fixed value of
θ
. When we wish to explicitly view this as a function of
θ
, we will instead call it the
likelihood
function:
L
(
θ
) =
L
(
θ
;
X, ~
y
) =
p
(
~
y
|
X
;
θ
)
.
Note that by the independence assumption on the
(
i
)
’s (and hence also the
y
(
i
)
’s given the
x
(
i
)
’s), this can also be written
L
(
θ
)
=
n
Y
i
=1
p
(
y
(
i
)
|
x
(
i
)
;
θ
)
=
n
Y
i
=1
1
√
2
πσ
exp
-
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
2
σ
2
.
Now, given this probabilistic model relating the
y
(
i
)
’s and the
x
(
i
)
’s, what
is a reasonable way of choosing our best guess of the parameters
θ
?
The
principal of
maximum likelihood
says that we should choose
θ
so as to
make the data as high probability as possible.
I.e., we should choose
θ
to
maximize
L
(
θ
).
16
Instead of maximizing
L
(
θ
), we can also maximize any strictly increasing
function of
L
(
θ
).
In particular, the derivations will be a bit simpler if we
instead maximize the
log likelihood
‘
(
θ
):
‘
(
θ
)
=
log
L
(
θ
)
=
log
n
Y
i
=1
1
√
2
πσ
exp
-
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
2
σ
2
=
n
X
i
=1
log
1
√
2
πσ
exp
-
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
2
σ
2
=
n
log
1
√
2
πσ
-
1
σ
2
·
1
2
n
X
i
=1
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
.
Hence, maximizing
‘
(
θ
) gives the same answer as minimizing
1
2
n
X
i
=1
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
,
which we recognize to be
J
(
θ
), our original least-squares cost function.
To summarize: Under the previous probabilistic assumptions on the data,
least-squares regression corresponds to finding the maximum likelihood esti-
mate of
θ
. This is thus one set of assumptions under which least-squares re-
gression can be justified as a very natural method that’s just doing maximum
likelihood estimation. (Note however that the probabilistic assumptions are
by no means
necessary
for least-squares to be a perfectly good and rational
procedure, and there may—and indeed there are—other natural assumptions
that can also be used to justify it.)
Note also that, in our previous discussion, our final choice of
θ
did not
depend on what was
σ
2
, and indeed we’d have arrived at the same result
even if
σ
2
were unknown.
We will use this fact again later, when we talk
about the exponential family and generalized linear models.
1.4
Locally weighted linear regression (optional
reading)
Consider the problem of predicting
y
from
x
∈
R
. The leftmost figure below
shows the result of fitting a
y
=
θ
0
+
θ
1
x
to a dataset. We see that the data
doesn’t really lie on straight line, and so the fit is not very good.
17
0
1
2
3
4
5
6
7
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
x
y
0
1
2
3
4
5
6
7
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
x
y
0
1
2
3
4
5
6
7
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
x
y
Instead, if we had added an extra feature
x
2
, and fit
y
=
θ
0
+
θ
1
x
+
θ
2
x
2
,
then we obtain a slightly better fit to the data. (See middle figure) Naively, it
might seem that the more features we add, the better. However, there is also
a danger in adding too many features: The rightmost figure is the result of
fitting a 5-th order polynomial
y
=
∑
5
j
=0
θ
j
x
j
. We see that even though the
fitted curve passes through the data perfectly, we would not expect this to
be a very good predictor of, say, housing prices (
y
) for different living areas
(
x
). Without formally defining what these terms mean, we’ll say the figure
on the left shows an instance of
underfitting
—in which the data clearly
shows structure not captured by the model—and the figure on the right is
an example of
overfitting
. (Later in this class, when we talk about learning
theory we’ll formalize some of these notions, and also define more carefully
just what it means for a hypothesis to be good or bad.)
As discussed previously, and as shown in the example above, the choice of
features is important to ensuring good performance of a learning algorithm.
(When we talk about model selection, we’ll also see algorithms for automat-
ically choosing a good set of features.)
In this section, let us briefly talk
about the locally weighted linear regression (LWR) algorithm which, assum-
ing there is sufficient training data, makes the choice of features less critical.
This treatment will be brief, since you’ll get a chance to explore some of the
properties of the LWR algorithm yourself in the homework.
In the original linear regression algorithm, to make a prediction at a query
point
x
(i.e., to evaluate
h
(
x
)), we would:
1. Fit
θ
to minimize
∑
i
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
.
2. Output
θ
T
x
.
In contrast, the locally weighted linear regression algorithm does the fol-
lowing:
1. Fit
θ
to minimize
∑
i
w
(
i
)
(
y
(
i
)
-
θ
T
x
(
i
)
)
2
.
2. Output
θ
T
x
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
18
Here, the
w
(
i
)
’s are non-negative valued
weights
. Intuitively, if
w
(
i
)
is large
for a particular value of
i
, then in picking
θ
, we’ll try hard to make (
y
(
i
)
-
θ
T
x
(
i
)
)
2
small.
If
w
(
i
)
is small, then the (
y
(
i
)
-
θ
T
x
(
i
)
)
2
error term will be
pretty much ignored in the fit.
A fairly standard choice for the weights is
4
w
(
i
)
= exp
-
(
x
(
i
)
-
x
)
2
2
τ
2
Note that the weights depend on the particular point
x
at which we’re trying
to evaluate
x
.
Moreover, if
|
x
(
i
)
-
x
|
is small, then
w
(
i
)
is close to 1; and
if
|
x
(
i
)
-
x
|
is large, then
w
(
i
)
is small.
Hence,
θ
is chosen giving a much
higher “weight” to the (errors on) training examples close to the query point
x
.
(Note also that while the formula for the weights takes a form that is
cosmetically similar to the density of a Gaussian distribution, the
w
(
i
)
’s do
not directly have anything to do with Gaussians, and in particular the
w
(
i
)
are not random variables, normally distributed or otherwise.) The parameter
τ
controls how quickly the weight of a training example falls off with distance
of its
x
(
i
)
from the query point
x
;
τ
is called the
bandwidth
parameter, and
is also something that you’ll get to experiment with in your homework.
Locally weighted linear regression is the first example we’re seeing of a
non-parametric
algorithm. The (unweighted) linear regression algorithm
that we saw earlier is known as a
parametric
learning algorithm, because
it has a fixed, finite number of parameters (the
θ
i
’s), which are fit to the
data.
Once we’ve fit the
θ
i
’s and stored them away, we no longer need to
keep the training data around to make future predictions.
In contrast, to
make predictions using locally weighted linear regression, we need to keep
the entire training set around. The term “non-parametric” (roughly) refers
to the fact that the amount of stuff we need to keep in order to represent the
hypothesis
h
grows linearly with the size of the training set.
4
If
x
is vector-valued, this is generalized to be
w
(
i
)
= exp(
-
(
x
(
i
)
-
x
)
T
(
x
(
i
)
-
x
)
/
(2
τ
2
)),
or
w
(
i
)
= exp(
-
(
x
(
i
)
-
x
)
T
Σ
-
1
(
x
(
i
)
-
x
)
/
(2
τ
2
)), for an appropriate choice of
τ
or Σ.
Chapter 2
Classification and logistic
regression
Let’s now talk about the classification problem. This is just like the regression
problem, except that the values
y
we now want to predict take on only
a small number of discrete values.
For now, we will focus on the
binary
classification
problem in which
y
can take on only two values, 0 and 1.
(Most of what we say here will also generalize to the multiple-class case.)
For instance, if we are trying to build a spam classifier for email, then
x
(
i
)
may be some features of a piece of email, and
y
may be 1 if it is a piece
of spam mail, and 0 otherwise. 0 is also called the
negative class
, and 1
the
positive class
, and they are sometimes also denoted by the symbols “-”
and “+.” Given
x
(
i
)
, the corresponding
y
(
i
)
is also called the
label
for the
training example.
2.1
Logistic regression
We could approach the classification problem ignoring the fact that
y
is
discrete-valued, and use our old linear regression algorithm to try to predict
y
given
x
.
However, it is easy to construct examples where this method
performs very poorly. Intuitively, it also doesn’t make sense for
h
θ
(
x
) to take
values larger than 1 or smaller than 0 when we know that
y
∈ {
0
,
1
}
.
To fix this, let’s change the form for our hypotheses
h
θ
(
x
). We will choose
h
θ
(
x
) =
g
(
θ
T
x
) =
1
1 +
e
-
θ
T
x
,
where
g
(
z
) =
1
1 +
e
-
z
19
20
is called the
logistic function
or the
sigmoid function
.
Here is a plot
showing
g
(
z
):
-5
-4
-3
-2
-1
0
1
2
3
4
5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
z
g(z)
Notice that
g
(
z
) tends towards 1 as
z
→ ∞
, and
g
(
z
) tends towards 0 as
z
→ -∞
. Moreover, g(z), and hence also
h
(
x
), is always bounded between
0 and 1. As before, we are keeping the convention of letting
x
0
= 1, so that
θ
T
x
=
θ
0
+
∑
d
j
=1
θ
j
x
j
.
For now, let’s take the choice of
g
as given. Other functions that smoothly
increase from 0 to 1 can also be used, but for a couple of reasons that we’ll see
later (when we talk about GLMs, and when we talk about generative learning
algorithms), the choice of the logistic function is a fairly natural one. Before
moving on, here’s a useful property of the derivative of the sigmoid function,
which we write as
g
0
:
g
0
(
z
)
=
d
dz
1
1 +
e
-
z
=
1
(1 +
e
-
z
)
2
(
e
-
z
)
=
1
(1 +
e
-
z
)
·
1
-
1
(1 +
e
-
z
)
=
g
(
z
)(1
-
g
(
z
))
.
So, given the logistic regression model, how do we fit
θ
for it? Following
how we saw least squares regression could be derived as the maximum like-
lihood estimator under a set of assumptions, let’s endow our classification
model with a set of probabilistic assumptions, and then fit the parameters
via maximum likelihood.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
21
Let us assume that
P
(
y
= 1
|
x
;
θ
)
=
h
θ
(
x
)
P
(
y
= 0
|
x
;
θ
)
=
1
-
h
θ
(
x
)
Note that this can be written more compactly as
p
(
y
|
x
;
θ
) = (
h
θ
(
x
))
y
(1
-
h
θ
(
x
))
1
-
y
Assuming that the
n
training examples were generated independently, we
can then write down the likelihood of the parameters as
L
(
θ
)
=
p
(
~
y
|
X
;
θ
)
=
n
Y
i
=1
p
(
y
(
i
)
|
x
(
i
)
;
θ
)
=
n
Y
i
=1
(
h
θ
(
x
(
i
)
)
)
y
(
i
)
(
1
-
h
θ
(
x
(
i
)
)
)
1
-
y
(
i
)
As before, it will be easier to maximize the log likelihood:
‘
(
θ
)
=
log
L
(
θ
)
=
n
X
i
=1
y
(
i
)
log
h
(
x
(
i
)
) + (1
-
y
(
i
)
) log(1
-
h
(
x
(
i
)
))
How do we maximize the likelihood? Similar to our derivation in the case
of linear regression, we can use gradient ascent. Written in vectorial notation,
our updates will therefore be given by
θ
:=
θ
+
α
∇
θ
‘
(
θ
). (Note the positive
rather than negative sign in the update formula, since we’re maximizing,
rather than minimizing, a function now.) Let’s start by working with just
one training example (
x, y
), and take derivatives to derive the stochastic
gradient ascent rule:
∂
∂θ
j
‘
(
θ
)
=
y
1
g
(
θ
T
x
)
-
(1
-
y
)
1
1
-
g
(
θ
T
x
)
∂
∂θ
j
g
(
θ
T
x
)
=
y
1
g
(
θ
T
x
)
-
(1
-
y
)
1
1
-
g
(
θ
T
x
)
g
(
θ
T
x
)(1
-
g
(
θ
T
x
))
∂
∂θ
j
θ
T
x
=
(
y
(1
-
g
(
θ
T
x
))
-
(1
-
y
)
g
(
θ
T
x
)
)
x
j
=
(
y
-
h
θ
(
x
))
x
j
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
22
Above, we used the fact that
g
0
(
z
) =
g
(
z
)(1
-
g
(
z
)). This therefore gives us
the stochastic gradient ascent rule
θ
j
:=
θ
j
+
α
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
j
If we compare this to the LMS update rule, we see that it looks identical; but
this is
not
the same algorithm, because
h
θ
(
x
(
i
)
) is now defined as a non-linear
function of
θ
T
x
(
i
)
. Nonetheless, it’s a little surprising that we end up with
the same update rule for a rather different algorithm and learning problem.
Is this coincidence, or is there a deeper reason behind this? We’ll answer this
when we get to GLM models.
2.2
Digression: the perceptron learning algo-
rithn
We now digress to talk briefly about an algorithm that’s of some historical
interest, and that we will also return to later when we talk about learning
theory.
Consider modifying the logistic regression method to “force” it to
output values that are either 0 or 1 or exactly. To do so, it seems natural to
change the definition of
g
to be the threshold function:
g
(
z
) =
1
if
z
≥
0
0
if
z <
0
If we then let
h
θ
(
x
) =
g
(
θ
T
x
) as before but using this modified definition of
g
, and if we use the update rule
θ
j
:=
θ
j
+
α
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
j
.
then we have the
perceptron learning algorithn
.
In the 1960s, this “perceptron” was argued to be a rough model for how
individual neurons in the brain work. Given how simple the algorithm is, it
will also provide a starting point for our analysis when we talk about learning
theory later in this class. Note however that even though the perceptron may
be cosmetically similar to the other algorithms we talked about, it is actually
a very different type of algorithm than logistic regression and least squares
linear regression; in particular, it is difficult to endow the perceptron’s predic-
tions with meaningful probabilistic interpretations, or derive the perceptron
as a maximum likelihood estimation algorithm.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
23
1
1.5
2
2.5
3
3.5
4
4.5
5
-10
0
10
20
30
40
50
60
x
f(x)
1
1.5
2
2.5
3
3.5
4
4.5
5
-10
0
10
20
30
40
50
60
x
f(x)
1
1.5
2
2.5
3
3.5
4
4.5
5
-10
0
10
20
30
40
50
60
x
f(x)
2.3
Another algorithm for maximizing
‘
(
θ
)
Returning to logistic regression with
g
(
z
) being the sigmoid function, let’s
now talk about a different algorithm for maximizing
‘
(
θ
).
To get us started, let’s consider Newton’s method for finding a zero of a
function. Specifically, suppose we have some function
f
:
R
7→
R
, and we
wish to find a value of
θ
so that
f
(
θ
) = 0. Here,
θ
∈
R
is a real number.
Newton’s method performs the following update:
θ
:=
θ
-
f
(
θ
)
f
0
(
θ
)
.
This method has a natural interpretation in which we can think of it as
approximating the function
f
via a linear function that is tangent to
f
at
the current guess
θ
, solving for where that linear function equals to zero, and
letting the next guess for
θ
be where that linear function is zero.
Here’s a picture of the Newton’s method in action:
In the leftmost figure, we see the function
f
plotted along with the line
y
= 0. We’re trying to find
θ
so that
f
(
θ
) = 0; the value of
θ
that achieves this
is about 1.3. Suppose we initialized the algorithm with
θ
= 4
.
5. Newton’s
method then fits a straight line tangent to
f
at
θ
= 4
.
5, and solves for the
where that line evaluates to 0. (Middle figure.) This give us the next guess
for
θ
, which is about 2.8. The rightmost figure shows the result of running
one more iteration, which the updates
θ
to about 1.8.
After a few more
iterations, we rapidly approach
θ
= 1
.
3.
Newton’s method gives a way of getting to
f
(
θ
) = 0. What if we want to
use it to maximize some function
‘
? The maxima of
‘
correspond to points
where its first derivative
‘
0
(
θ
) is zero. So, by letting
f
(
θ
) =
‘
0
(
θ
), we can use
the same algorithm to maximize
‘
, and we obtain update rule:
θ
:=
θ
-
‘
0
(
θ
)
‘
00
(
θ
)
.
(Something to think about:
How would this change if we wanted to use
Newton’s method to minimize rather than maximize a function?)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
24
Lastly, in our logistic regression setting,
θ
is vector-valued, so we need to
generalize Newton’s method to this setting. The generalization of Newton’s
method to this multidimensional setting (also called the Newton-Raphson
method) is given by
θ
:=
θ
-
H
-
1
∇
θ
‘
(
θ
)
.
Here,
∇
θ
‘
(
θ
) is, as usual, the vector of partial derivatives of
‘
(
θ
) with respect
to the
θ
i
’s; and
H
is an
d
-by-
d
matrix (actually,
d
+1
-
by
-
d+1, assuming that
we include the intercept term) called the
Hessian
, whose entries are given
by
H
ij
=
∂
2
‘
(
θ
)
∂θ
i
∂θ
j
.
Newton’s method typically enjoys faster convergence than (batch) gra-
dient descent, and requires many fewer iterations to get very close to the
minimum. One iteration of Newton’s can, however, be more expensive than
one iteration of gradient descent, since it requires finding and inverting an
d
-by-
d
Hessian; but so long as
d
is not too large, it is usually much faster
overall. When Newton’s method is applied to maximize the logistic regres-
sion log likelihood function
‘
(
θ
), the resulting method is also called
Fisher
scoring
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 3
Generalized linear models
So far, we’ve seen a regression example, and a classification example. In the
regression example, we had
y
|
x
;
θ
∼ N
(
μ, σ
2
), and in the classification one,
y
|
x
;
θ
∼
Bernoulli(
φ
), for some appropriate definitions of
μ
and
φ
as functions
of
x
and
θ
.
In this section, we will show that both of these methods are
special cases of a broader family of models, called Generalized Linear Models
(GLMs).
1
We will also show how other models in the GLM family can be
derived and applied to other classification and regression problems.
3.1
The exponential family
To work our way up to GLMs, we will begin by defining exponential family
distributions. We say that a class of distributions is in the exponential family
if it can be written in the form
p
(
y
;
η
) =
b
(
y
) exp(
η
T
T
(
y
)
-
a
(
η
))
(3.1)
Here,
η
is called the
natural parameter
(also called the
canonical param-
eter
) of the distribution;
T
(
y
) is the
sufficient statistic
(for the distribu-
tions we consider, it will often be the case that
T
(
y
) =
y
); and
a
(
η
) is the
log
partition function
. The quantity
e
-
a
(
η
)
essentially plays the role of a nor-
malization constant, that makes sure the distribution
p
(
y
;
η
) sums/integrates
over
y
to 1.
A fixed choice of
T
,
a
and
b
defines a
family
(or set) of distributions that
is parameterized by
η
; as we vary
η
, we then get different distributions within
this family.
1
The presentation of the material in this section takes inspiration from Michael I.
Jordan,
Learning in graphical models
(unpublished book draft), and also McCullagh and
Nelder,
Generalized Linear Models (2nd ed.)
.
25
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
26
We now show that the Bernoulli and the Gaussian distributions are ex-
amples of exponential family distributions. The Bernoulli distribution with
mean
φ
, written Bernoulli(
φ
), specifies a distribution over
y
∈ {
0
,
1
}
, so that
p
(
y
= 1;
φ
) =
φ
;
p
(
y
= 0;
φ
) = 1
-
φ
.
As we vary
φ
, we obtain Bernoulli
distributions with different means. We now show that this class of Bernoulli
distributions, ones obtained by varying
φ
, is in the exponential family; i.e.,
that there is a choice of
T
,
a
and
b
so that Equation (3.1) becomes exactly
the class of Bernoulli distributions.
We write the Bernoulli distribution as:
p
(
y
;
φ
)
=
φ
y
(1
-
φ
)
1
-
y
=
exp(
y
log
φ
+ (1
-
y
) log(1
-
φ
))
=
exp
log
φ
1
-
φ
y
+ log(1
-
φ
)
.
Thus, the natural parameter is given by
η
= log(
φ/
(1
-
φ
)). Interestingly, if
we invert this definition for
η
by solving for
φ
in terms of
η
, we obtain
φ
=
1
/
(1 +
e
-
η
). This is the familiar sigmoid function! This will come up again
when we derive logistic regression as a GLM. To complete the formulation
of the Bernoulli distribution as an exponential family distribution, we also
have
T
(
y
)
=
y
a
(
η
)
=
-
log(1
-
φ
)
=
log(1 +
e
η
)
b
(
y
)
=
1
This shows that the Bernoulli distribution can be written in the form of
Equation (3.1), using an appropriate choice of
T
,
a
and
b
.
Let’s now move on to consider the Gaussian distribution.
Recall that,
when deriving linear regression, the value of
σ
2
had no effect on our final
choice of
θ
and
h
θ
(
x
). Thus, we can choose an arbitrary value for
σ
2
without
changing anything. To simplify the derivation below, let’s set
σ
2
= 1.
2
We
2
If we leave
σ
2
as a variable, the Gaussian distribution can also be shown to be in the
exponential family, where
η
∈
R
2
is now a 2-dimension vector that depends on both
μ
and
σ
. For the purposes of GLMs, however, the
σ
2
parameter can also be treated by considering
a more general definition of the exponential family:
p
(
y
;
η, τ
) =
b
(
a, τ
) exp((
η
T
T
(
y
)
-
a
(
η
))
/c
(
τ
)). Here,
τ
is called the
dispersion parameter
, and for the Gaussian,
c
(
τ
) =
σ
2
;
but given our simplification above, we won’t need the more general definition for the
examples we will consider here.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
27
then have:
p
(
y
;
μ
)
=
1
√
2
π
exp
-
1
2
(
y
-
μ
)
2
=
1
√
2
π
exp
-
1
2
y
2
·
exp
μy
-
1
2
μ
2
Thus, we see that the Gaussian is in the exponential family, with
η
=
μ
T
(
y
)
=
y
a
(
η
)
=
μ
2
/
2
=
η
2
/
2
b
(
y
)
=
(1
/
√
2
π
) exp(
-
y
2
/
2)
.
There’re many other distributions that are members of the exponen-
tial family: The multinomial (which we’ll see later), the Poisson (for mod-
elling count-data; also see the problem set); the gamma and the exponen-
tial (for modelling continuous, non-negative random variables, such as time-
intervals); the beta and the Dirichlet (for distributions over probabilities);
and many more.
In the next section, we will describe a general “recipe”
for constructing models in which
y
(given
x
and
θ
) comes from any of these
distributions.
3.2
Constructing GLMs
Suppose you would like to build a model to estimate the number
y
of cus-
tomers arriving in your store (or number of page-views on your website) in
any given hour, based on certain features
x
such as store promotions, recent
advertising, weather, day-of-week, etc. We know that the Poisson distribu-
tion usually gives a good model for numbers of visitors. Knowing this, how
can we come up with a model for our problem? Fortunately, the Poisson is an
exponential family distribution, so we can apply a Generalized Linear Model
(GLM). In this section, we will we will describe a method for constructing
GLM models for problems such as these.
More generally, consider a classification or regression problem where we
would like to predict the value of some random variable
y
as a function of
x
.
To derive a GLM for this problem, we will make the following three
assumptions about the conditional distribution of
y
given
x
and about our
model:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
28
1.
y
|
x
;
θ
∼
ExponentialFamily(
η
). I.e., given
x
and
θ
, the distribution of
y
follows some exponential family distribution, with parameter
η
.
2. Given
x
, our goal is to predict the expected value of
T
(
y
) given
x
.
In most of our examples, we will have
T
(
y
) =
y
, so this means we
would like the prediction
h
(
x
) output by our learned hypothesis
h
to
satisfy
h
(
x
) = E[
y
|
x
].
(Note that this assumption is satisfied in the
choices for
h
θ
(
x
) for both logistic regression and linear regression. For
instance, in logistic regression, we had
h
θ
(
x
) =
p
(
y
= 1
|
x
;
θ
) = 0
·
p
(
y
=
0
|
x
;
θ
) + 1
·
p
(
y
= 1
|
x
;
θ
) = E[
y
|
x
;
θ
].)
3. The natural parameter
η
and the inputs
x
are related linearly:
η
=
θ
T
x
.
(Or, if
η
is vector-valued, then
η
i
=
θ
T
i
x
.)
The third of these assumptions might seem the least well justified of
the above, and it might be better thought of as a “design choice” in our
recipe for designing GLMs, rather than as an assumption per se.
These
three assumptions/design choices will allow us to derive a very elegant class
of learning algorithms, namely GLMs, that have many desirable properties
such as ease of learning. Furthermore, the resulting models are often very
effective for modelling different types of distributions over
y
; for example, we
will shortly show that both logistic regression and ordinary least squares can
both be derived as GLMs.
3.2.1
Ordinary least squares
To show that ordinary least squares is a special case of the GLM family
of models, consider the setting where the target variable
y
(also called the
response variable
in GLM terminology) is continuous, and we model the
conditional distribution of
y
given
x
as a Gaussian
N
(
μ, σ
2
). (Here,
μ
may
depend
x
.)
So, we let the
ExponentialFamily
(
η
) distribution above be
the Gaussian distribution. As we saw previously, in the formulation of the
Gaussian as an exponential family distribution, we had
μ
=
η
. So, we have
h
θ
(
x
)
=
E
[
y
|
x
;
θ
]
=
μ
=
η
=
θ
T
x.
The first equality follows from Assumption 2, above; the second equality
follows from the fact that
y
|
x
;
θ
∼ N
(
μ, σ
2
), and so its expected value is given
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
29
by
μ
; the third equality follows from Assumption 1 (and our earlier derivation
showing that
μ
=
η
in the formulation of the Gaussian as an exponential
family distribution); and the last equality follows from Assumption 3.
3.2.2
Logistic regression
We now consider logistic regression. Here we are interested in binary classifi-
cation, so
y
∈ {
0
,
1
}
. Given that
y
is binary-valued, it therefore seems natural
to choose the Bernoulli family of distributions to model the conditional dis-
tribution of
y
given
x
.
In our formulation of the Bernoulli distribution as
an exponential family distribution, we had
φ
= 1
/
(1 +
e
-
η
). Furthermore,
note that if
y
|
x
;
θ
∼
Bernoulli(
φ
), then E[
y
|
x
;
θ
] =
φ
. So, following a similar
derivation as the one for ordinary least squares, we get:
h
θ
(
x
)
=
E
[
y
|
x
;
θ
]
=
φ
=
1
/
(1 +
e
-
η
)
=
1
/
(1 +
e
-
θ
T
x
)
So, this gives us hypothesis functions of the form
h
θ
(
x
) = 1
/
(1 +
e
-
θ
T
x
). If
you are previously wondering how we came up with the form of the logistic
function 1
/
(1 +
e
-
z
), this gives one answer: Once we assume that
y
condi-
tioned on
x
is Bernoulli, it arises as a consequence of the definition of GLMs
and exponential family distributions.
To introduce a little more terminology, the function
g
giving the distri-
bution’s mean as a function of the natural parameter (
g
(
η
) = E[
T
(
y
);
η
])
is called the
canonical response function
. Its inverse,
g
-
1
, is called the
canonical link function
.
Thus, the canonical response function for the
Gaussian family is just the identify function; and the canonical response
function for the Bernoulli is the logistic function.
3
3.2.3
Softmax regression
Let’s look at one more example of a GLM. Consider a classification problem
in which the response variable
y
can take on any one of
k
values, so
y
∈
{
1
,
2
, . . . , k
}
. For example, rather than classifying email into the two classes
3
Many texts use
g
to denote the link function, and
g
-
1
to denote the response function;
but the notation we’re using here, inherited from the early machine learning literature,
will be more consistent with the notation used in the rest of the class.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
30
spam or not-spam—which would have been a binary classification problem—
we might want to classify it into three classes, such as spam, personal mail,
and work-related mail. The response variable is still discrete, but can now
take on more than two values. We will thus model it as distributed according
to a multinomial distribution.
Let’s derive a GLM for modelling this type of multinomial data. To do
so, we will begin by expressing the multinomial as an exponential family
distribution.
To parameterize a multinomial over
k
possible outcomes, one could use
k
parameters
φ
1
, . . . , φ
k
specifying the probability of each of the outcomes.
However, these parameters would be redundant, or more formally, they would
not be independent (since knowing any
k
-
1 of the
φ
i
’s uniquely determines
the last one, as they must satisfy
∑
k
i
=1
φ
i
= 1).
So, we will instead pa-
rameterize the multinomial with only
k
-
1 parameters,
φ
1
, . . . , φ
k
-
1
, where
φ
i
=
p
(
y
=
i
;
φ
), and
p
(
y
=
k
;
φ
) = 1
-
∑
k
-
1
i
=1
φ
i
. For notational convenience,
we will also let
φ
k
= 1
-
∑
k
-
1
i
=1
φ
i
, but we should keep in mind that this is
not a parameter, and that it is fully specified by
φ
1
, . . . , φ
k
-
1
.
To express the multinomial as an exponential family distribution, we will
define
T
(
y
)
∈
R
k
-
1
as follows:
T
(1) =
1
0
0
.
.
.
0
, T
(2) =
0
1
0
.
.
.
0
, T
(3) =
0
0
1
.
.
.
0
,
· · ·
, T
(
k
-
1) =
0
0
0
.
.
.
1
, T
(
k
) =
0
0
0
.
.
.
0
,
Unlike our previous examples, here we do
not
have
T
(
y
) =
y
; also,
T
(
y
) is
now a
k
-
1 dimensional vector, rather than a real number. We will write
(
T
(
y
))
i
to denote the
i
-th element of the vector
T
(
y
).
We introduce one more very useful piece of notation. An indicator func-
tion 1
{·}
takes on a value of 1 if its argument is true, and 0 otherwise
(1
{
True
}
= 1, 1
{
False
}
= 0).
For example, 1
{
2 = 3
}
= 0, and 1
{
3 =
5
-
2
}
= 1. So, we can also write the relationship between
T
(
y
) and
y
as
(
T
(
y
))
i
= 1
{
y
=
i
}
. (Before you continue reading, please make sure you un-
derstand why this is true!) Further, we have that E[(
T
(
y
))
i
] =
P
(
y
=
i
) =
φ
i
.
We are now ready to show that the multinomial is a member of the
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
31
exponential family. We have:
p
(
y
;
φ
)
=
φ
1
{
y
=1
}
1
φ
1
{
y
=2
}
2
· · ·
φ
1
{
y
=
k
}
k
=
φ
1
{
y
=1
}
1
φ
1
{
y
=2
}
2
· · ·
φ
1
-
∑
k
-
1
i
=1
1
{
y
=
i
}
k
=
φ
(
T
(
y
))
1
1
φ
(
T
(
y
))
2
2
· · ·
φ
1
-
∑
k
-
1
i
=1
(
T
(
y
))
i
k
=
exp((
T
(
y
))
1
log(
φ
1
) + (
T
(
y
))
2
log(
φ
2
) +
· · ·
+
1
-
∑
k
-
1
i
=1
(
T
(
y
))
i
log(
φ
k
))
=
exp((
T
(
y
))
1
log(
φ
1
/φ
k
) + (
T
(
y
))
2
log(
φ
2
/φ
k
) +
· · ·
+ (
T
(
y
))
k
-
1
log(
φ
k
-
1
/φ
k
) + log(
φ
k
))
=
b
(
y
) exp(
η
T
T
(
y
)
-
a
(
η
))
where
η
=
log(
φ
1
/φ
k
)
log(
φ
2
/φ
k
)
.
.
.
log(
φ
k
-
1
/φ
k
)
,
a
(
η
)
=
-
log(
φ
k
)
b
(
y
)
=
1
.
This completes our formulation of the multinomial as an exponential family
distribution.
The link function is given (for
i
= 1
, . . . , k
) by
η
i
= log
φ
i
φ
k
.
For convenience, we have also defined
η
k
= log(
φ
k
/φ
k
) = 0. To invert the
link function and derive the response function, we therefore have that
e
η
i
=
φ
i
φ
k
φ
k
e
η
i
=
φ
i
(3.2)
φ
k
k
X
i
=1
e
η
i
=
k
X
i
=1
φ
i
= 1
This implies that
φ
k
= 1
/
∑
k
i
=1
e
η
i
, which can be substituted back into Equa-
tion (3.2) to give the response function
φ
i
=
e
η
i
∑
k
j
=1
e
η
j
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
32
This function mapping from the
η
’s to the
φ
’s is called the
softmax
function.
To complete our model, we use Assumption 3, given earlier, that the
η
i
’s
are linearly related to the
x
’s.
So, have
η
i
=
θ
T
i
x
(for
i
= 1
, . . . , k
-
1),
where
θ
1
, . . . , θ
k
-
1
∈
R
d
+1
are the parameters of our model. For notational
convenience, we can also define
θ
k
= 0, so that
η
k
=
θ
T
k
x
= 0, as given
previously. Hence, our model assumes that the conditional distribution of
y
given
x
is given by
p
(
y
=
i
|
x
;
θ
)
=
φ
i
=
e
η
i
∑
k
j
=1
e
η
j
=
e
θ
T
i
x
∑
k
j
=1
e
θ
T
j
x
(3.3)
This model, which applies to classification problems where
y
∈ {
1
, . . . , k
}
, is
called
softmax regression
. It is a generalization of logistic regression.
Our hypothesis will output
h
θ
(
x
)
=
E[
T
(
y
)
|
x
;
θ
]
=
E
1
{
y
= 1
}
1
{
y
= 2
}
.
.
.
1
{
y
=
k
-
1
}
x
;
θ
=
φ
1
φ
2
.
.
.
φ
k
-
1
=
exp(
θ
T
1
x
)
∑
k
j
=1
exp(
θ
T
j
x
)
exp(
θ
T
2
x
)
∑
k
j
=1
exp(
θ
T
j
x
)
.
.
.
exp(
θ
T
k
-
1
x
)
∑
k
j
=1
exp(
θ
T
j
x
)
.
In other words, our hypothesis will output the estimated probability that
p
(
y
=
i
|
x
;
θ
), for every value of
i
= 1
, . . . , k
. (Even though
h
θ
(
x
) as defined
above is only
k
-
1 dimensional, clearly
p
(
y
=
k
|
x
;
θ
) can be obtained as
1
-
∑
k
-
1
i
=1
φ
i
.)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
33
Lastly, let’s discuss parameter fitting. Similar to our original derivation
of ordinary least squares and logistic regression, if we have a training set of
n
examples
{
(
x
(
i
)
, y
(
i
)
);
i
= 1
, . . . , n
}
and would like to learn the parameters
θ
i
of this model, we would begin by writing down the log-likelihood
‘
(
θ
)
=
n
X
i
=1
log
p
(
y
(
i
)
|
x
(
i
)
;
θ
)
=
n
X
i
=1
log
k
Y
l
=1
e
θ
T
l
x
(
i
)
∑
k
j
=1
e
θ
T
j
x
(
i
)
!
1
{
y
(
i
)
=
l
}
To obtain the second line above, we used the definition for
p
(
y
|
x
;
θ
) given
in Equation (3.3). We can now obtain the maximum likelihood estimate of
the parameters by maximizing
‘
(
θ
) in terms of
θ
, using a method such as
gradient ascent or Newton’s method.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 4
Generative learning algorithms
So far, we’ve mainly been talking about learning algorithms that model
p
(
y
|
x
;
θ
), the conditional distribution of
y
given
x
.
For instance, logistic
regression modeled
p
(
y
|
x
;
θ
) as
h
θ
(
x
) =
g
(
θ
T
x
) where
g
is the sigmoid func-
tion. In these notes, we’ll talk about a different type of learning algorithm.
Consider a classification problem in which we want to learn to distinguish
between elephants (
y
= 1) and dogs (
y
= 0), based on some features of
an animal.
Given a training set, an algorithm like logistic regression or
the perceptron algorithm (basically) tries to find a straight line—that is, a
decision boundary—that separates the elephants and dogs. Then, to classify
a new animal as either an elephant or a dog, it checks on which side of the
decision boundary it falls, and makes its prediction accordingly.
Here’s a different approach. First, looking at elephants, we can build a
model of what elephants look like.
Then, looking at dogs, we can build a
separate model of what dogs look like. Finally, to classify a new animal, we
can match the new animal against the elephant model, and match it against
the dog model, to see whether the new animal looks more like the elephants
or more like the dogs we had seen in the training set.
Algorithms that try to learn
p
(
y
|
x
) directly (such as logistic regression),
or algorithms that try to learn mappings directly from the space of inputs
X
to the labels
{
0
,
1
}
, (such as the perceptron algorithm) are called
discrim-
inative
learning algorithms. Here, we’ll talk about algorithms that instead
try to model
p
(
x
|
y
) (and
p
(
y
)).
These algorithms are called
generative
learning algorithms.
For instance, if
y
indicates whether an example is a
dog (0) or an elephant (1), then
p
(
x
|
y
= 0) models the distribution of dogs’
features, and
p
(
x
|
y
= 1) models the distribution of elephants’ features.
After modeling
p
(
y
) (called the
class priors
) and
p
(
x
|
y
), our algorithm
34
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
35
can then use Bayes rule to derive the posterior distribution on
y
given
x
:
p
(
y
|
x
) =
p
(
x
|
y
)
p
(
y
)
p
(
x
)
.
Here, the denominator is given by
p
(
x
) =
p
(
x
|
y
= 1)
p
(
y
= 1) +
p
(
x
|
y
=
0)
p
(
y
= 0) (you should be able to verify that this is true from the standard
properties of probabilities), and thus can also be expressed in terms of the
quantities
p
(
x
|
y
) and
p
(
y
) that we’ve learned. Actually, if were calculating
p
(
y
|
x
) in order to make a prediction, then we don’t actually need to calculate
the denominator, since
arg max
y
p
(
y
|
x
)
=
arg max
y
p
(
x
|
y
)
p
(
y
)
p
(
x
)
=
arg max
y
p
(
x
|
y
)
p
(
y
)
.
4.1
Gaussian discriminant analysis
The first generative learning algorithm that we’ll look at is Gaussian discrim-
inant analysis (GDA). In this model, we’ll assume that
p
(
x
|
y
) is distributed
according to a multivariate normal distribution. Let’s talk briefly about the
properties of multivariate normal distributions before moving on to the GDA
model itself.
4.1.1
The multivariate normal distribution
The multivariate normal distribution in
d
-dimensions, also called the multi-
variate Gaussian distribution, is parameterized by a
mean vector
μ
∈
R
d
and a
covariance matrix
Σ
∈
R
d
×
d
, where Σ
≥
0 is symmetric and positive
semi-definite. Also written “
N
(
μ,
Σ)”, its density is given by:
p
(
x
;
μ,
Σ) =
1
(2
π
)
d/
2
|
Σ
|
1
/
2
exp
-
1
2
(
x
-
μ
)
T
Σ
-
1
(
x
-
μ
)
.
In the equation above, “
|
Σ
|
” denotes the determinant of the matrix Σ.
For a random variable
X
distributed
N
(
μ,
Σ), the mean is (unsurpris-
ingly) given by
μ
:
E[
X
] =
Z
x
x p
(
x
;
μ,
Σ)
dx
=
μ
The
covariance
of a vector-valued random variable
Z
is defined as Cov(
Z
) =
E[(
Z
-
E[
Z
])(
Z
-
E[
Z
])
T
]. This generalizes the notion of the variance of a
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
36
real-valued random variable. The covariance can also be defined as Cov(
Z
) =
E[
ZZ
T
]
-
(E[
Z
])(E[
Z
])
T
. (You should be able to prove to yourself that these
two definitions are equivalent.) If
X
∼ N
(
μ,
Σ), then
Cov(
X
) = Σ
.
Here are some examples of what the density of a Gaussian distribution
looks like:
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
The left-most figure shows a Gaussian with mean zero (that is, the 2x1
zero-vector) and covariance matrix Σ =
I
(the 2x2 identity matrix). A Gaus-
sian with zero mean and identity covariance is also called the
standard nor-
mal distribution
. The middle figure shows the density of a Gaussian with
zero mean and Σ = 0
.
6
I
; and in the rightmost figure shows one with , Σ = 2
I
.
We see that as Σ becomes larger, the Gaussian becomes more “spread-out,”
and as it becomes smaller, the distribution becomes more “compressed.”
Let’s look at some more examples.
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
The figures above show Gaussians with mean 0, and with covariance
matrices respectively
Σ =
1
0
0
1
;
Σ =
1
0.5
0.5
1
;
Σ =
1
0.8
0.8
1
.
The leftmost figure shows the familiar standard normal distribution, and we
see that as we increase the off-diagonal entry in Σ, the density becomes more
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
37
“compressed” towards the 45
◦
line (given by
x
1
=
x
2
). We can see this more
clearly when we look at the contours of the same three densities:
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
Here’s one last set of examples generated by varying Σ:
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
The plots above used, respectively,
Σ =
1
-0.5
-0.5
1
;
Σ =
1
-0.8
-0.8
1
;
Σ =
3
0.8
0.8
1
.
From the leftmost and middle figures, we see that by decreasing the off-
diagonal elements of the covariance matrix, the density now becomes “com-
pressed” again, but in the opposite direction.
Lastly, as we vary the pa-
rameters, more generally the contours will form ellipses (the rightmost figure
showing an example).
As our last set of examples, fixing Σ =
I
, by varying
μ
, we can also move
the mean of the density around.
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
-3
-2
-1
0
1
2
3
-3
-2
-1
0
1
2
3
0.05
0.1
0.15
0.2
0.25
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
38
The figures above were generated using Σ =
I
, and respectively
μ
=
1
0
;
μ
=
-0.5
0
;
μ
=
-1
-1.5
.
4.1.2
The Gaussian discriminant analysis model
When we have a classification problem in which the input features
x
are
continuous-valued random variables, we can then use the Gaussian Discrim-
inant Analysis (GDA) model, which models
p
(
x
|
y
) using a multivariate nor-
mal distribution. The model is:
y
∼
Bernoulli(
φ
)
x
|
y
= 0
∼
N
(
μ
0
,
Σ)
x
|
y
= 1
∼
N
(
μ
1
,
Σ)
Writing out the distributions, this is:
p
(
y
)
=
φ
y
(1
-
φ
)
1
-
y
p
(
x
|
y
= 0)
=
1
(2
π
)
d/
2
|
Σ
|
1
/
2
exp
-
1
2
(
x
-
μ
0
)
T
Σ
-
1
(
x
-
μ
0
)
p
(
x
|
y
= 1)
=
1
(2
π
)
d/
2
|
Σ
|
1
/
2
exp
-
1
2
(
x
-
μ
1
)
T
Σ
-
1
(
x
-
μ
1
)
Here, the parameters of our model are
φ
, Σ,
μ
0
and
μ
1
.
(Note that while
there’re two different mean vectors
μ
0
and
μ
1
, this model is usually applied
using only one covariance matrix Σ.) The log-likelihood of the data is given
by
‘
(
φ, μ
0
, μ
1
,
Σ)
=
log
n
Y
i
=1
p
(
x
(
i
)
, y
(
i
)
;
φ, μ
0
, μ
1
,
Σ)
=
log
n
Y
i
=1
p
(
x
(
i
)
|
y
(
i
)
;
μ
0
, μ
1
,
Σ)
p
(
y
(
i
)
;
φ
)
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
39
By maximizing
‘
with respect to the parameters, we find the maximum like-
lihood estimate of the parameters (see problem set 1) to be:
φ
=
1
n
n
X
i
=1
1
{
y
(
i
)
= 1
}
μ
0
=
∑
n
i
=1
1
{
y
(
i
)
= 0
}
x
(
i
)
∑
n
i
=1
1
{
y
(
i
)
= 0
}
μ
1
=
∑
n
i
=1
1
{
y
(
i
)
= 1
}
x
(
i
)
∑
n
i
=1
1
{
y
(
i
)
= 1
}
Σ
=
1
n
n
X
i
=1
(
x
(
i
)
-
μ
y
(
i
)
)(
x
(
i
)
-
μ
y
(
i
)
)
T
.
Pictorially, what the algorithm is doing can be seen in as follows:
-2
-1
0
1
2
3
4
5
6
7
-7
-6
-5
-4
-3
-2
-1
0
1
Shown in the figure are the training set, as well as the contours of the
two Gaussian distributions that have been fit to the data in each of the
two classes. Note that the two Gaussians have contours that are the same
shape and orientation, since they share a covariance matrix Σ, but they have
different means
μ
0
and
μ
1
.
Also shown in the figure is the straight line
giving the decision boundary at which
p
(
y
= 1
|
x
) = 0
.
5.
On one side of
the boundary, we’ll predict
y
= 1 to be the most likely outcome, and on the
other side, we’ll predict
y
= 0.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
40
4.1.3
Discussion: GDA and logistic regression
The GDA model has an interesting relationship to logistic regression. If we
view the quantity
p
(
y
= 1
|
x
;
φ, μ
0
, μ
1
,
Σ) as a function of
x
, we’ll find that it
can be expressed in the form
p
(
y
= 1
|
x
;
φ,
Σ
, μ
0
, μ
1
) =
1
1 + exp(
-
θ
T
x
)
,
where
θ
is some appropriate function of
φ,
Σ
, μ
0
, μ
1
.
1
This is exactly the form
that logistic regression—a discriminative algorithm—used to model
p
(
y
=
1
|
x
).
When would we prefer one model over another? GDA and logistic regres-
sion will, in general, give different decision boundaries when trained on the
same dataset. Which is better?
We just argued that if
p
(
x
|
y
) is multivariate gaussian (with shared Σ),
then
p
(
y
|
x
) necessarily follows a logistic function.
The converse, however,
is not true; i.e.,
p
(
y
|
x
) being a logistic function does not imply
p
(
x
|
y
) is
multivariate gaussian. This shows that GDA makes
stronger
modeling as-
sumptions about the data than does logistic regression.
It turns out that
when these modeling assumptions are correct, then GDA will find better fits
to the data, and is a better model. Specifically, when
p
(
x
|
y
) is indeed gaus-
sian (with shared Σ), then GDA is
asymptotically efficient
. Informally,
this means that in the limit of very large training sets (large
n
), there is no
algorithm that is strictly better than GDA (in terms of, say, how accurately
they estimate
p
(
y
|
x
)).
In particular, it can be shown that in this setting,
GDA will be a better algorithm than logistic regression; and more generally,
even for small training set sizes, we would generally expect GDA to better.
In contrast, by making significantly weaker assumptions, logistic regres-
sion is also more
robust
and less sensitive to incorrect modeling assumptions.
There are many different sets of assumptions that would lead to
p
(
y
|
x
) taking
the form of a logistic function. For example, if
x
|
y
= 0
∼
Poisson(
λ
0
), and
x
|
y
= 1
∼
Poisson(
λ
1
), then
p
(
y
|
x
) will be logistic. Logistic regression will
also work well on Poisson data like this. But if we were to use GDA on such
data—and fit Gaussian distributions to such non-Gaussian data—then the
results will be less predictable, and GDA may (or may not) do well.
To summarize: GDA makes stronger modeling assumptions, and is more
data efficient (i.e., requires less training data to learn “well”) when the mod-
eling assumptions are correct or at least approximately correct.
Logistic
1
This uses the convention of redefining the
x
(
i
)
’s on the right-hand-side to be (
d
+ 1)-
dimensional vectors by adding the extra coordinate
x
(
i
)
0
= 1; see problem set 1.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
41
regression makes weaker assumptions, and is significantly more robust to
deviations from modeling assumptions.
Specifically, when the data is in-
deed non-Gaussian, then in the limit of large datasets, logistic regression will
almost always do better than GDA. For this reason, in practice logistic re-
gression is used more often than GDA. (Some related considerations about
discriminative vs.
generative models also apply for the Naive Bayes algo-
rithm that we discuss next, but the Naive Bayes algorithm is still considered
a very good, and is certainly also a very popular, classification algorithm.)
4.2
Naive bayes
In GDA, the feature vectors
x
were continuous, real-valued vectors.
Let’s
now talk about a different learning algorithm in which the
x
j
’s are discrete-
valued.
For our motivating example, consider building an email spam filter using
machine learning. Here, we wish to classify messages according to whether
they are unsolicited commercial (spam) email, or non-spam email.
After
learning to do this, we can then have our mail reader automatically filter
out the spam messages and perhaps place them in a separate mail folder.
Classifying emails is one example of a broader set of problems called
text
classification
.
Let’s say we have a training set (a set of emails labeled as spam or non-
spam).
We’ll begin our construction of our spam filter by specifying the
features
x
j
used to represent an email.
We will represent an email via a feature vector whose length is equal to
the number of words in the dictionary. Specifically, if an email contains the
j
-th word of the dictionary, then we will set
x
j
= 1; otherwise, we let
x
j
= 0.
For instance, the vector
x
=
1
0
0
.
.
.
1
.
.
.
0
a
aardvark
aardwolf
.
.
.
buy
.
.
.
zygmurgy
is used to represent an email that contains the words “a” and “buy,” but not
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
42
“aardvark,” “aardwolf” or “zygmurgy.”
2
The set of words encoded into the
feature vector is called the
vocabulary
, so the dimension of
x
is equal to
the size of the vocabulary.
Having chosen our feature vector, we now want to build a generative
model. So, we have to model
p
(
x
|
y
). But if we have, say, a vocabulary of
50000 words, then
x
∈ {
0
,
1
}
50000
(
x
is a 50000-dimensional vector of 0’s and
1’s), and if we were to model
x
explicitly with a multinomial distribution over
the 2
50000
possible outcomes, then we’d end up with a (2
50000
-
1)-dimensional
parameter vector. This is clearly too many parameters.
To model
p
(
x
|
y
), we will therefore make a very strong assumption. We will
assume that the
x
i
’s are conditionally independent given
y
. This assumption
is called the
Naive Bayes (NB) assumption
, and the resulting algorithm is
called the
Naive Bayes classifier
. For instance, if
y
= 1 means spam email;
“buy” is word 2087 and “price” is word 39831; then we are assuming that if
I tell you
y
= 1 (that a particular piece of email is spam), then knowledge
of
x
2087
(knowledge of whether “buy” appears in the message) will have no
effect on your beliefs about the value of
x
39831
(whether “price” appears).
More formally, this can be written
p
(
x
2087
|
y
) =
p
(
x
2087
|
y, x
39831
). (Note that
this is
not
the same as saying that
x
2087
and
x
39831
are independent, which
would have been written “
p
(
x
2087
) =
p
(
x
2087
|
x
39831
)”; rather, we are only
assuming that
x
2087
and
x
39831
are conditionally independent
given
y
.)
We now have:
p
(
x
1
, . . . , x
50000
|
y
)
=
p
(
x
1
|
y
)
p
(
x
2
|
y, x
1
)
p
(
x
3
|
y, x
1
, x
2
)
· · ·
p
(
x
50000
|
y, x
1
, . . . , x
49999
)
=
p
(
x
1
|
y
)
p
(
x
2
|
y
)
p
(
x
3
|
y
)
· · ·
p
(
x
50000
|
y
)
=
d
Y
j
=1
p
(
x
j
|
y
)
The first equality simply follows from the usual properties of probabilities,
and the second equality used the NB assumption. We note that even though
2
Actually, rather than looking through an English dictionary for the list of all English
words, in practice it is more common to look through our training set and encode in our
feature vector only the words that occur at least once there.
Apart from reducing the
number of words modeled and hence reducing our computational and space requirements,
this also has the advantage of allowing us to model/include as a feature many words
that may appear in your email (such as “cs229”) but that you won’t find in a dictionary.
Sometimes (as in the homework), we also exclude the very high frequency words (which
will be words like “the,” “of,” “and”; these high frequency, “content free” words are called
stop words
) since they occur in so many documents and do little to indicate whether an
email is spam or non-spam.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
43
the Naive Bayes assumption is an extremely strong assumptions, the resulting
algorithm works well on many problems.
Our model is parameterized by
φ
j
|
y
=1
=
p
(
x
j
= 1
|
y
= 1),
φ
j
|
y
=0
=
p
(
x
j
=
1
|
y
= 0), and
φ
y
=
p
(
y
= 1). As usual, given a training set
{
(
x
(
i
)
, y
(
i
)
);
i
=
1
, . . . , n
}
, we can write down the joint likelihood of the data:
L
(
φ
y
, φ
j
|
y
=0
, φ
j
|
y
=1
) =
n
Y
i
=1
p
(
x
(
i
)
, y
(
i
)
)
.
Maximizing this with respect to
φ
y
, φ
j
|
y
=0
and
φ
j
|
y
=1
gives the maximum
likelihood estimates:
φ
j
|
y
=1
=
∑
n
i
=1
1
{
x
(
i
)
j
= 1
∧
y
(
i
)
= 1
}
∑
n
i
=1
1
{
y
(
i
)
= 1
}
φ
j
|
y
=0
=
∑
n
i
=1
1
{
x
(
i
)
j
= 1
∧
y
(
i
)
= 0
}
∑
n
i
=1
1
{
y
(
i
)
= 0
}
φ
y
=
∑
n
i
=1
1
{
y
(
i
)
= 1
}
n
In the equations above, the “
∧
” symbol means “and.” The parameters have
a very natural interpretation. For instance,
φ
j
|
y
=1
is just the fraction of the
spam (
y
= 1) emails in which word
j
does appear.
Having fit all these parameters, to make a prediction on a new example
with features
x
, we then simply calculate
p
(
y
= 1
|
x
)
=
p
(
x
|
y
= 1)
p
(
y
= 1)
p
(
x
)
=
Q
d
j
=1
p
(
x
j
|
y
= 1)
p
(
y
= 1)
Q
d
j
=1
p
(
x
j
|
y
= 1)
p
(
y
= 1) +
Q
d
j
=1
p
(
x
j
|
y
= 0)
p
(
y
= 0)
,
and pick whichever class has the higher posterior probability.
Lastly, we note that while we have developed the Naive Bayes algorithm
mainly for the case of problems where the features
x
j
are binary-valued, the
generalization to where
x
j
can take values in
{
1
,
2
, . . . , k
j
}
is straightforward.
Here, we would simply model
p
(
x
j
|
y
) as multinomial rather than as Bernoulli.
Indeed, even if some original input attribute (say, the living area of a house,
as in our earlier example) were continuous valued, it is quite common to
discretize
it—that is, turn it into a small set of discrete values—and apply
Naive Bayes. For instance, if we use some feature
x
j
to represent living area,
we might discretize the continuous values as follows:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
44
Living area (sq. feet)
<
400
400-800
800-1200
1200-1600
>
1600
x
i
1
2
3
4
5
Thus, for a house with living area 890 square feet, we would set the value
of the corresponding feature
x
j
to 3.
We can then apply the Naive Bayes
algorithm, and model
p
(
x
j
|
y
) with a multinomial distribution, as described
previously.
When the original, continuous-valued attributes are not well-
modeled by a multivariate normal distribution, discretizing the features and
using Naive Bayes (instead of GDA) will often result in a better classifier.
4.2.1
Laplace smoothing
The Naive Bayes algorithm as we have described it will work fairly well
for many problems, but there is a simple change that makes it work much
better, especially for text classification. Let’s briefly discuss a problem with
the algorithm in its current form, and then talk about how we can fix it.
Consider spam/email classification, and let’s suppose that, we are in the
year of 20xx, after completing CS229 and having done excellent work on the
project, you decide around May 20xx to submit work you did to the NeurIPS
conference for publication.
3
Because you end up discussing the conference
in your emails, you also start getting messages with the word “neurips”
in it.
But this is your first NeurIPS paper, and until this time, you had
not previously seen any emails containing the word “neurips”; in particular
“neurips” did not ever appear in your training set of spam/non-spam emails.
Assuming that “neurips” was the 35000th word in the dictionary, your Naive
Bayes spam filter therefore had picked its maximum likelihood estimates of
the parameters
φ
35000
|
y
to be
φ
35000
|
y
=1
=
∑
n
i
=1
1
{
x
(
i
)
35000
= 1
∧
y
(
i
)
= 1
}
∑
n
i
=1
1
{
y
(
i
)
= 1
}
= 0
φ
35000
|
y
=0
=
∑
n
i
=1
1
{
x
(
i
)
35000
= 1
∧
y
(
i
)
= 0
}
∑
n
i
=1
1
{
y
(
i
)
= 0
}
= 0
I.e., because it has never seen “neurips” before in either spam or non-spam
training examples, it thinks the probability of seeing it in either type of email
is zero.
Hence, when trying to decide if one of these messages containing
3
NeurIPS is one of the top machine learning conferences. The deadline for submitting
a paper is typically in May-June.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
45
“neurips” is spam, it calculates the class posterior probabilities, and obtains
p
(
y
= 1
|
x
)
=
Q
d
j
=1
p
(
x
j
|
y
= 1)
p
(
y
= 1)
Q
d
j
=1
p
(
x
j
|
y
= 1)
p
(
y
= 1) +
Q
d
j
=1
p
(
x
j
|
y
= 0)
p
(
y
= 0)
=
0
0
.
This is because each of the terms “
Q
d
j
=1
p
(
x
j
|
y
)” includes a term
p
(
x
35000
|
y
) =
0 that is multiplied into it. Hence, our algorithm obtains 0
/
0, and doesn’t
know how to make a prediction.
Stating the problem more broadly, it is statistically a bad idea to esti-
mate the probability of some event to be zero just because you haven’t seen
it before in your finite training set. Take the problem of estimating the mean
of a multinomial random variable
z
taking values in
{
1
, . . . , k
}
. We can pa-
rameterize our multinomial with
φ
j
=
p
(
z
=
j
). Given a set of
n
independent
observations
{
z
(1)
, . . . , z
(
n
)
}
, the maximum likelihood estimates are given by
φ
j
=
∑
n
i
=1
1
{
z
(
i
)
=
j
}
n
.
As we saw previously, if we were to use these maximum likelihood estimates,
then some of the
φ
j
’s might end up as zero, which was a problem. To avoid
this, we can use
Laplace smoothing
, which replaces the above estimate
with
φ
j
=
1 +
∑
n
i
=1
1
{
z
(
i
)
=
j
}
k
+
n
.
Here, we’ve added 1 to the numerator, and
k
to the denominator. Note that
∑
k
j
=1
φ
j
= 1 still holds (check this yourself!), which is a desirable property
since the
φ
j
’s are estimates for probabilities that we know must sum to 1.
Also,
φ
j
6
= 0 for all values of
j
, solving our problem of probabilities being
estimated as zero. Under certain (arguably quite strong) conditions, it can
be shown that the Laplace smoothing actually gives the optimal estimator
of the
φ
j
’s.
Returning to our Naive Bayes classifier, with Laplace smoothing, we
therefore obtain the following estimates of the parameters:
φ
j
|
y
=1
=
1 +
∑
n
i
=1
1
{
x
(
i
)
j
= 1
∧
y
(
i
)
= 1
}
2 +
∑
n
i
=1
1
{
y
(
i
)
= 1
}
φ
j
|
y
=0
=
1 +
∑
n
i
=1
1
{
x
(
i
)
j
= 1
∧
y
(
i
)
= 0
}
2 +
∑
n
i
=1
1
{
y
(
i
)
= 0
}
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
46
(In practice, it usually doesn’t matter much whether we apply Laplace smooth-
ing to
φ
y
or not, since we will typically have a fair fraction each of spam and
non-spam messages, so
φ
y
will be a reasonable estimate of
p
(
y
= 1) and will
be quite far from 0 anyway.)
4.2.2
Event models for text classification (optional read-
ing)
To close off our discussion of generative learning algorithms, let’s talk about
one more model that is specifically for text classification. While Naive Bayes
as we’ve presented it will work well for many classification problems, for text
classification, there is a related model that does even better.
In the specific context of text classification, Naive Bayes as presented uses
the what’s called the
Bernoulli event model
(or sometimes
multi-variate
Bernoulli event model
). In this model, we assumed that the way an email
is generated is that first it is randomly determined (according to the class
priors
p
(
y
)) whether a spammer or non-spammer will send you your next
message. Then, the person sending the email runs through the dictionary,
deciding whether to include each word
j
in that email independently and
according to the probabilities
p
(
x
j
= 1
|
y
) =
φ
j
|
y
. Thus, the probability of a
message was given by
p
(
y
)
Q
d
j
=1
p
(
x
j
|
y
).
Here’s a different model, called the
Multinomial event model
.
To
describe this model, we will use a different notation and set of features for
representing emails. We let
x
j
denote the identity of the
j
-th word in the
email. Thus,
x
j
is now an integer taking values in
{
1
, . . . ,
|
V
|}
, where
|
V
|
is the size of our vocabulary (dictionary). An email of
d
words is now rep-
resented by a vector (
x
1
, x
2
, . . . , x
d
) of length
d
; note that
d
can vary for
different documents. For instance, if an email starts with “A NeurIPS . . . ,”
then
x
1
= 1 (“a” is the first word in the dictionary), and
x
2
= 35000 (if
“neurips” is the 35000th word in the dictionary).
In the multinomial event model, we assume that the way an email is
generated is via a random process in which spam/non-spam is first deter-
mined (according to
p
(
y
)) as before. Then, the sender of the email writes the
email by first generating
x
1
from some multinomial distribution over words
(
p
(
x
1
|
y
)). Next, the second word
x
2
is chosen independently of
x
1
but from
the same multinomial distribution, and similarly for
x
3
,
x
4
, and so on, until
all
d
words of the email have been generated. Thus, the overall probability of
a message is given by
p
(
y
)
Q
d
j
=1
p
(
x
j
|
y
). Note that this formula looks like the
one we had earlier for the probability of a message under the Bernoulli event
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
47
model, but that the terms in the formula now mean very different things. In
particular
x
j
|
y
is now a multinomial, rather than a Bernoulli distribution.
The parameters for our new model are
φ
y
=
p
(
y
) as before,
φ
k
|
y
=1
=
p
(
x
j
=
k
|
y
= 1) (for any
j
) and
φ
k
|
y
=0
=
p
(
x
j
=
k
|
y
= 0). Note that we have
assumed that
p
(
x
j
|
y
) is the same for all values of
j
(i.e., that the distribution
according to which a word is generated does not depend on its position
j
within the email).
If we are given a training set
{
(
x
(
i
)
, y
(
i
)
);
i
= 1
, . . . , n
}
where
x
(
i
)
=
(
x
(
i
)
1
, x
(
i
)
2
, . . . , x
(
i
)
d
i
) (here,
d
i
is the number of words in the
i
-training example),
the likelihood of the data is given by
L
(
φ
y
, φ
k
|
y
=0
, φ
k
|
y
=1
)
=
n
Y
i
=1
p
(
x
(
i
)
, y
(
i
)
)
=
n
Y
i
=1
d
i
Y
j
=1
p
(
x
(
i
)
j
|
y
;
φ
k
|
y
=0
, φ
k
|
y
=1
)
!
p
(
y
(
i
)
;
φ
y
)
.
Maximizing this yields the maximum likelihood estimates of the parameters:
φ
k
|
y
=1
=
∑
n
i
=1
∑
d
i
j
=1
1
{
x
(
i
)
j
=
k
∧
y
(
i
)
= 1
}
∑
n
i
=1
1
{
y
(
i
)
= 1
}
d
i
φ
k
|
y
=0
=
∑
n
i
=1
∑
d
i
j
=1
1
{
x
(
i
)
j
=
k
∧
y
(
i
)
= 0
}
∑
n
i
=1
1
{
y
(
i
)
= 0
}
d
i
φ
y
=
∑
n
i
=1
1
{
y
(
i
)
= 1
}
n
.
If we were to apply Laplace smoothing (which is needed in practice for good
performance) when estimating
φ
k
|
y
=0
and
φ
k
|
y
=1
, we add 1 to the numerators
and
|
V
|
to the denominators, and obtain:
φ
k
|
y
=1
=
1 +
∑
n
i
=1
∑
d
i
j
=1
1
{
x
(
i
)
j
=
k
∧
y
(
i
)
= 1
}
|
V
|
+
∑
n
i
=1
1
{
y
(
i
)
= 1
}
d
i
φ
k
|
y
=0
=
1 +
∑
n
i
=1
∑
d
i
j
=1
1
{
x
(
i
)
j
=
k
∧
y
(
i
)
= 0
}
|
V
|
+
∑
n
i
=1
1
{
y
(
i
)
= 0
}
d
i
.
While not necessarily the very best classification algorithm, the Naive Bayes
classifier often works surprisingly well. It is often also a very good “first thing
to try,” given its simplicity and ease of implementation.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 5
Kernel methods
5.1
Feature maps
Recall that in our discussion about linear regression, we considered the prob-
lem of predicting the price of a house (denoted by
y
) from the living area of
the house (denoted by
x
), and we fit a linear function of
x
to the training
data. What if the price
y
can be more accurately represented as a
non-linear
function of
x
? In this case, we need a more expressive family of models than
linear models.
We start by considering fitting cubic functions
y
=
θ
3
x
3
+
θ
2
x
2
+
θ
1
x
+
θ
0
.
It turns out that we can view the cubic function as a linear function over
the a different set of feature variables (defined below).
Concretely, let the
function
φ
:
R
→
R
4
be defined as
φ
(
x
) =
1
x
x
2
x
3
∈
R
4
.
(5.1)
Let
θ
∈
R
4
be the vector containing
θ
0
, θ
1
, θ
2
, θ
3
as entries. Then we can
rewrite the cubic function in
x
as:
θ
3
x
3
+
θ
2
x
2
+
θ
1
x
+
θ
0
=
θ
T
φ
(
x
)
Thus, a cubic function of the variable
x
can be viewed as a linear function
over the variables
φ
(
x
). To distinguish between these two sets of variables,
in the context of kernel methods, we will call the “original” input value the
input
attributes
of a problem (in this case,
x
, the living area). When the
48
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
49
original input is mapped to some new set of quantities
φ
(
x
), we will call those
new quantities the
features
variables. (Unfortunately, different authors use
different terms to describe these two things in different contexts.) We will
call
φ
a
feature map
, which maps the attributes to the features.
5.2
LMS (least mean squares) with features
We will derive the gradient descent algorithm for fitting the model
θ
T
φ
(
x
).
First recall that for ordinary least square problem where we were to fit
θ
T
x
,
the batch gradient descent update is (see the first lecture note for its deriva-
tion):
θ
:=
θ
+
α
n
X
i
=1
(
y
(
i
)
-
h
θ
(
x
(
i
)
)
)
x
(
i
)
:=
θ
+
α
n
X
i
=1
(
y
(
i
)
-
θ
T
x
(
i
)
)
x
(
i
)
.
(5.2)
Let
φ
:
R
d
→
R
p
be a feature map that maps attribute
x
(in
R
d
) to the
features
φ
(
x
) in
R
p
. (In the motivating example in the previous subsection,
we have
d
= 1 and
p
= 4.) Now our goal is to fit the function
θ
T
φ
(
x
), with
θ
being a vector in
R
p
instead of
R
d
. We can replace all the occurrences of
x
(
i
)
in the algorithm above by
φ
(
x
(
i
)
) to obtain the new update:
θ
:=
θ
+
α
n
X
i
=1
(
y
(
i
)
-
θ
T
φ
(
x
(
i
)
)
)
φ
(
x
(
i
)
)
(5.3)
Similarly, the corresponding stochastic gradient descent update rule is
θ
:=
θ
+
α
(
y
(
i
)
-
θ
T
φ
(
x
(
i
)
)
)
φ
(
x
(
i
)
)
(5.4)
5.3
LMS with the kernel trick
The gradient descent update, or stochastic gradient update above becomes
computationally expensive when the features
φ
(
x
) is high-dimensional. For
example, consider the direct extension of the feature map in equation (5.1)
to high-dimensional input
x
: suppose
x
∈
R
d
, and let
φ
(
x
) be the vector that
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
50
contains all the monomials of
x
with degree
≤
3
φ
(
x
) =
1
x
1
x
2
.
.
.
x
2
1
x
1
x
2
x
1
x
3
.
.
.
x
2
x
1
.
.
.
x
3
1
x
2
1
x
2
.
.
.
.
(5.5)
The dimension of the features
φ
(
x
) is on the order of
d
3
.
1
This is a pro-
hibitively long vector for computational purpose — when
d
= 1000, each
update requires at least computing and storing a 1000
3
= 10
9
dimensional
vector, which is 10
6
times slower than the update rule for for ordinary least
squares updates (5.2).
It may appear at first that such
d
3
runtime per update and memory usage
are inevitable, because the vector
θ
itself is of dimension
p
≈
d
3
, and we may
need to update every entry of
θ
and store it. However, we will introduce the
kernel trick with which we will not need to store
θ
explicitly, and the runtime
can be significantly improved.
For simplicity, we assume the initialize the value
θ
= 0, and we focus
on the iterative update (5.3). The main observation is that at any time,
θ
can be represented as a linear combination of the vectors
φ
(
x
(1)
)
, . . . , φ
(
x
(
n
)
).
Indeed, we can show this inductively as follows. At initialization,
θ
= 0 =
∑
n
i
=1
0
·
φ
(
x
(
i
)
). Assume at some point,
θ
can be represented as
θ
=
n
X
i
=1
β
i
φ
(
x
(
i
)
)
(5.6)
1
Here, for simplicity, we include all the monomials with repetitions (so that, e.g.,
x
1
x
2
x
3
and
x
2
x
3
x
1
both appear in
φ
(
x
)). Therefore, there are totally 1 +
d
+
d
2
+
d
3
entries in
φ
(
x
).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
51
for some
β
1
, . . . , β
n
∈
R
. Then we claim that in the next round,
θ
is still a
linear combination of
φ
(
x
(1)
)
, . . . , φ
(
x
(
n
)
) because
θ
:=
θ
+
α
n
X
i
=1
(
y
(
i
)
-
θ
T
φ
(
x
(
i
)
)
)
φ
(
x
(
i
)
)
=
n
X
i
=1
β
i
φ
(
x
(
i
)
) +
α
n
X
i
=1
(
y
(
i
)
-
θ
T
φ
(
x
(
i
)
)
)
φ
(
x
(
i
)
)
=
n
X
i
=1
(
β
i
+
α
(
y
(
i
)
-
θ
T
φ
(
x
(
i
)
)
)
)
|
{z
}
new
β
i
φ
(
x
(
i
)
)
(5.7)
You may realize that our general strategy is to implicitly represent the
p
-
dimensional vector
θ
by a set of coefficients
β
1
, . . . , β
n
. Towards doing this,
we derive the update rule of the coefficients
β
1
, . . . , β
n
. Using the equation
above, we see that the new
β
i
depends on the old one via
β
i
:=
β
i
+
α
(
y
(
i
)
-
θ
T
φ
(
x
(
i
)
)
)
(5.8)
Here we still have the old
θ
on the RHS of the equation.
Replacing
θ
by
θ
=
∑
n
j
=1
β
j
φ
(
x
(
j
)
) gives
∀
i
∈ {
1
, . . . , n
}
, β
i
:=
β
i
+
α
y
(
i
)
-
n
X
j
=1
β
j
φ
(
x
(
j
)
)
T
φ
(
x
(
i
)
)
!
We often rewrite
φ
(
x
(
j
)
)
T
φ
(
x
(
i
)
) as
h
φ
(
x
(
j
)
)
, φ
(
x
(
i
)
)
i
to emphasize that it’s the
inner product of the two feature vectors. Viewing
β
i
’s as the new representa-
tion of
θ
, we have successfully translated the batch gradient descent algorithm
into an algorithm that updates the value of
β
iteratively. It may appear that
at every iteration, we still need to compute the values of
h
φ
(
x
(
j
)
)
, φ
(
x
(
i
)
)
i
for
all pairs of
i, j
, each of which may take roughly
O
(
p
) operation. However,
two important properties come to rescue:
1. We can pre-compute the pairwise inner products
h
φ
(
x
(
j
)
)
, φ
(
x
(
i
)
)
i
for all
pairs of
i, j
before the loop starts.
2. For the feature map
φ
defined in (5.5) (or many other interesting fea-
ture maps), computing
h
φ
(
x
(
j
)
)
, φ
(
x
(
i
)
)
i
can be efficient and does not
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
52
necessarily require computing
φ
(
x
(
i
)
) explicitly. This is because:
h
φ
(
x
)
, φ
(
z
)
i
= 1 +
d
X
i
=1
x
i
z
i
+
X
i,j
∈{
1
,...,d
}
x
i
x
j
z
i
z
j
+
X
i,j,k
∈{
1
,...,d
}
x
i
x
j
x
k
z
i
z
j
z
k
= 1 +
d
X
i
=1
x
i
z
i
+
d
X
i
=1
x
i
z
i
!
2
+
d
X
i
=1
x
i
z
i
!
3
= 1 +
h
x, z
i
+
h
x, z
i
2
+
h
x, z
i
3
(5.9)
Therefore, to compute
h
φ
(
x
)
, φ
(
z
)
i
, we can first compute
h
x, z
i
with
O
(
d
) time and then take another constant number of operations to com-
pute 1 +
h
x, z
i
+
h
x, z
i
2
+
h
x, z
i
3
.
As you will see, the inner products between the features
h
φ
(
x
)
, φ
(
z
)
i
are
essential here. We define the
Kernel
corresponding to the feature map
φ
as
a function that maps
X × X →
R
satisfying:
2
K
(
x, z
)
,
h
φ
(
x
)
, φ
(
z
)
i
(5.10)
To wrap up the discussion, we write the down the final algorithm as
follows:
1. Compute all the values
K
(
x
(
i
)
, x
(
j
)
)
,
h
φ
(
x
(
i
)
)
, φ
(
x
(
j
)
)
i
using equa-
tion (5.9) for all
i, j
∈ {
1
, . . . , n
}
. Set
β
:= 0.
2.
Loop:
∀
i
∈ {
1
, . . . , n
}
, β
i
:=
β
i
+
α
y
(
i
)
-
n
X
j
=1
β
j
K
(
x
(
i
)
, x
(
j
)
)
!
(5.11)
Or in vector notation, letting
K
be the
n
×
n
matrix with
K
ij
=
K
(
x
(
i
)
, x
(
j
)
), we have
β
:=
β
+
α
(
~
y
-
Kβ
)
With the algorithm above, we can update the representation
β
of the
vector
θ
efficiently with
O
(
n
) time per update. Finally, we need to show that
2
Recall that
X
is the space of the input
x
. In our running example,
X
=
R
d
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
53
the knowledge of the representation
β
suffices to compute the prediction
θ
T
φ
(
x
). Indeed, we have
θ
T
φ
(
x
) =
n
X
i
=1
β
i
φ
(
x
(
i
)
)
T
φ
(
x
) =
n
X
i
=1
β
i
K
(
x
(
i
)
, x
)
(5.12)
You may realize that fundamentally all we need to know about the feature
map
φ
(
·
) is encapsulated in the corresponding kernel function
K
(
·
,
·
).
We
will expand on this in the next section.
5.4
Properties of kernels
In the last subsection, we started with an explicitly defined feature map
φ
,
which induces the kernel function
K
(
x, z
)
,
h
φ
(
x
)
, φ
(
z
)
i
. Then we saw that
the kernel function is so intrinsic so that as long as the kernel function is
defined, the whole training algorithm can be written entirely in the language
of the kernel without referring to the feature map
φ
, so can the prediction of
a test example
x
(equation (5.12).)
Therefore, it would be tempted to define other kernel function
K
(
·
,
·
) and
run the algorithm (5.11). Note that the algorithm (5.11) does not need to
explicitly access the feature map
φ
, and therefore we only need to ensure the
existence of the feature map
φ
, but do not necessarily need to be able to
explicitly write
φ
down.
What kinds of functions
K
(
·
,
·
) can correspond to some feature map
φ
? In
other words, can we tell if there is some feature mapping
φ
so that
K
(
x, z
) =
φ
(
x
)
T
φ
(
z
) for all
x
,
z
?
If we can answer this question by giving a precise characterization of valid
kernel functions, then we can completely change the interface of selecting
feature maps
φ
to the interface of selecting kernel function
K
. Concretely,
we can pick a function
K
, verify that it satisfies the characterization (so
that there exists a feature map
φ
that
K
corresponds to), and then we can
run update rule (5.11).
The benefit here is that we don’t have to be able
to compute
φ
or write it down analytically, and we only need to know its
existence. We will answer this question at the end of this subsection after
we go through several concrete examples of kernels.
Suppose
x, z
∈
R
d
, and let’s first consider the function
K
(
·
,
·
) defined as:
K
(
x, z
) = (
x
T
z
)
2
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
54
We can also write this as
K
(
x, z
)
=
d
X
i
=1
x
i
z
i
! d
X
j
=1
x
j
z
j
!
=
d
X
i
=1
d
X
j
=1
x
i
x
j
z
i
z
j
=
d
X
i,j
=1
(
x
i
x
j
)(
z
i
z
j
)
Thus, we see that
K
(
x, z
) =
h
φ
(
x
)
, φ
(
z
)
i
is the kernel function that corre-
sponds to the the feature mapping
φ
given (shown here for the case of
d
= 3)
by
φ
(
x
) =
x
1
x
1
x
1
x
2
x
1
x
3
x
2
x
1
x
2
x
2
x
2
x
3
x
3
x
1
x
3
x
2
x
3
x
3
.
Revisiting the computational efficiency perspective of kernel, note that whereas
calculating the high-dimensional
φ
(
x
) requires
O
(
d
2
) time, finding
K
(
x, z
)
takes only
O
(
d
) time—linear in the dimension of the input attributes.
For another related example, also consider
K
(
·
,
·
) defined by
K
(
x, z
)
=
(
x
T
z
+
c
)
2
=
d
X
i,j
=1
(
x
i
x
j
)(
z
i
z
j
) +
d
X
i
=1
(
√
2
cx
i
)(
√
2
cz
i
) +
c
2
.
(Check this yourself.) This function
K
is a kernel function that corresponds
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
55
to the feature mapping (again shown for
d
= 3)
φ
(
x
) =
x
1
x
1
x
1
x
2
x
1
x
3
x
2
x
1
x
2
x
2
x
2
x
3
x
3
x
1
x
3
x
2
x
3
x
3
√
2
cx
1
√
2
cx
2
√
2
cx
3
c
,
and the parameter
c
controls the relative weighting between the
x
i
(first
order) and the
x
i
x
j
(second order) terms.
More broadly, the kernel
K
(
x, z
) = (
x
T
z
+
c
)
k
corresponds to a feature
mapping to an
(
d
+
k
k
)
feature space, corresponding of all monomials of the
form
x
i
1
x
i
2
. . . x
i
k
that are up to order
k
. However, despite working in this
O
(
d
k
)-dimensional space, computing
K
(
x, z
) still takes only
O
(
d
) time, and
hence we never need to explicitly represent feature vectors in this very high
dimensional feature space.
Kernels as similarity metrics.
Now, let’s talk about a slightly different
view of kernels. Intuitively, (and there are things wrong with this intuition,
but nevermind), if
φ
(
x
) and
φ
(
z
) are close together, then we might expect
K
(
x, z
) =
φ
(
x
)
T
φ
(
z
) to be large. Conversely, if
φ
(
x
) and
φ
(
z
) are far apart—
say nearly orthogonal to each other—then
K
(
x, z
) =
φ
(
x
)
T
φ
(
z
) will be small.
So, we can think of
K
(
x, z
) as some measurement of how similar are
φ
(
x
)
and
φ
(
z
), or of how similar are
x
and
z
.
Given this intuition, suppose that for some learning problem that you’re
working on, you’ve come up with some function
K
(
x, z
) that you think might
be a reasonable measure of how similar
x
and
z
are. For instance, perhaps
you chose
K
(
x, z
) = exp
-
||
x
-
z
||
2
2
σ
2
.
This is a reasonable measure of
x
and
z
’s similarity, and is close to 1 when
x
and
z
are close, and near 0 when
x
and
z
are far apart. Does there exist
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
56
a feature map
φ
such that the kernel
K
defined above satisfies
K
(
x, z
) =
φ
(
x
)
T
φ
(
z
)? In this particular example, the answer is yes. This kernel is called
the
Gaussian kernel
, and corresponds to an infinite dimensional feature
mapping
φ
.
We will give a precise characterization about what properties
a function
K
needs to satisfy so that it can be a valid kernel function that
corresponds to some feature map
φ
.
Necessary conditions for valid kernels.
Suppose for now that
K
is
indeed a valid kernel corresponding to some feature mapping
φ
, and we will
first see what properties it satisfies. Now, consider some finite set of
n
points
(not necessarily the training set)
{
x
(1)
, . . . , x
(
n
)
}
, and let a square,
n
-by-
n
matrix
K
be defined so that its (
i, j
)-entry is given by
K
ij
=
K
(
x
(
i
)
, x
(
j
)
).
This matrix is called the
kernel matrix
. Note that we’ve overloaded the
notation and used
K
to denote both the kernel function
K
(
x, z
) and the
kernel matrix
K
, due to their obvious close relationship.
Now, if
K
is a valid kernel, then
K
ij
=
K
(
x
(
i
)
, x
(
j
)
) =
φ
(
x
(
i
)
)
T
φ
(
x
(
j
)
) =
φ
(
x
(
j
)
)
T
φ
(
x
(
i
)
) =
K
(
x
(
j
)
, x
(
i
)
) =
K
ji
, and hence
K
must be symmetric. More-
over, letting
φ
k
(
x
) denote the
k
-th coordinate of the vector
φ
(
x
), we find that
for any vector
z
, we have
z
T
Kz
=
X
i
X
j
z
i
K
ij
z
j
=
X
i
X
j
z
i
φ
(
x
(
i
)
)
T
φ
(
x
(
j
)
)
z
j
=
X
i
X
j
z
i
X
k
φ
k
(
x
(
i
)
)
φ
k
(
x
(
j
)
)
z
j
=
X
k
X
i
X
j
z
i
φ
k
(
x
(
i
)
)
φ
k
(
x
(
j
)
)
z
j
=
X
k
X
i
z
i
φ
k
(
x
(
i
)
)
!
2
≥
0
.
The second-to-last step uses the fact that
∑
i,j
a
i
a
j
= (
∑
i
a
i
)
2
for
a
i
=
z
i
φ
k
(
x
(
i
)
). Since
z
was arbitrary, this shows that
K
is positive semi-definite
(
K
≥
0).
Hence, we’ve shown that if
K
is a valid kernel (i.e., if it corresponds to
some feature mapping
φ
), then the corresponding kernel matrix
K
∈
R
n
×
n
is symmetric positive semidefinite.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
57
Sufficient conditions for valid kernels.
More generally, the condition
above turns out to be not only a necessary, but also a sufficient, condition
for
K
to be a valid kernel (also called a Mercer kernel). The following result
is due to Mercer.
3
Theorem (Mercer).
Let
K
:
R
d
×
R
d
7→
R
be given.
Then for
K
to be a valid (Mercer) kernel, it is necessary and sufficient that for any
{
x
(1)
, . . . , x
(
n
)
}
, (
n <
∞
), the corresponding kernel matrix is symmetric pos-
itive semi-definite.
Given a function
K
, apart from trying to find a feature mapping
φ
that
corresponds to it, this theorem therefore gives another way of testing if it is
a valid kernel.
You’ll also have a chance to play with these ideas more in
problem set 2.
In class, we also briefly talked about a couple of other examples of ker-
nels.
For instance, consider the digit recognition problem, in which given
an image (16x16 pixels) of a handwritten digit (0-9), we have to figure out
which digit it was. Using either a simple polynomial kernel
K
(
x, z
) = (
x
T
z
)
k
or the Gaussian kernel, SVMs were able to obtain extremely good perfor-
mance on this problem.
This was particularly surprising since the input
attributes
x
were just 256-dimensional vectors of the image pixel intensity
values, and the system had no prior knowledge about vision, or even about
which pixels are adjacent to which other ones.
Another example that we
briefly talked about in lecture was that if the objects
x
that we are trying
to classify are strings (say,
x
is a list of amino acids, which strung together
form a protein), then it seems hard to construct a reasonable, “small” set of
features for most learning algorithms, especially if different strings have dif-
ferent lengths. However, consider letting
φ
(
x
) be a feature vector that counts
the number of occurrences of each length-
k
substring in
x
. If we’re consid-
ering strings of English letters, then there are 26
k
such strings. Hence,
φ
(
x
)
is a 26
k
dimensional vector; even for moderate values of
k
, this is probably
too big for us to efficiently work with. (e.g., 26
4
≈
460000.) However, using
(dynamic programming-ish) string matching algorithms, it is possible to ef-
ficiently compute
K
(
x, z
) =
φ
(
x
)
T
φ
(
z
), so that we can now implicitly work
in this 26
k
-dimensional feature space, but without ever explicitly computing
feature vectors in this space.
3
Many texts present Mercer’s theorem in a slightly more complicated form involving
L
2
functions, but when the input attributes take values in
R
d
, the version given here is
equivalent.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
58
Application of kernel methods:
We’ve seen the application of kernels
to linear regression. In the next part, we will introduce the support vector
machines to which kernels can be directly applied. dwell too much longer on
it here. In fact, the idea of kernels has significantly broader applicability than
linear regression and SVMs. Specifically, if you have any learning algorithm
that you can write in terms of only inner products
h
x, z
i
between input
attribute vectors, then by replacing this with
K
(
x, z
) where
K
is a kernel,
you can “magically” allow your algorithm to work efficiently in the high
dimensional feature space corresponding to
K
. For instance, this kernel trick
can be applied with the perceptron to derive a kernel perceptron algorithm.
Many of the algorithms that we’ll see later in this class will also be amenable
to this method, which has come to be known as the “kernel trick.”
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 6
Support vector machines
This set of notes presents the Support Vector Machine (SVM) learning al-
gorithm. SVMs are among the best (and many believe are indeed the best)
“off-the-shelf” supervised learning algorithms. To tell the SVM story, we’ll
need to first talk about margins and the idea of separating data with a large
“gap.” Next, we’ll talk about the optimal margin classifier, which will lead
us into a digression on Lagrange duality. We’ll also see kernels, which give
a way to apply SVMs efficiently in very high dimensional (such as infinite-
dimensional) feature spaces, and finally, we’ll close off the story with the
SMO algorithm, which gives an efficient implementation of SVMs.
6.1
Margins: intuition
We’ll start our story on SVMs by talking about margins. This section will
give the intuitions about margins and about the “confidence” of our predic-
tions; these ideas will be made formal in Section 6.3.
Consider logistic regression, where the probability
p
(
y
= 1
|
x
;
θ
) is mod-
eled by
h
θ
(
x
) =
g
(
θ
T
x
). We then predict “1” on an input
x
if and only if
h
θ
(
x
)
≥
0
.
5, or equivalently, if and only if
θ
T
x
≥
0.
Consider a positive
training example (
y
= 1). The larger
θ
T
x
is, the larger also is
h
θ
(
x
) =
p
(
y
=
1
|
x
;
θ
), and thus also the higher our degree of “confidence” that the label is 1.
Thus, informally we can think of our prediction as being very confident that
y
= 1 if
θ
T
x
0.
Similarly, we think of logistic regression as confidently
predicting
y
= 0, if
θ
T
x
0. Given a training set, again informally it seems
that we’d have found a good fit to the training data if we can find
θ
so that
θ
T
x
(
i
)
0 whenever
y
(
i
)
= 1, and
θ
T
x
(
i
)
0 whenever
y
(
i
)
= 0, since this
would reflect a very confident (and correct) set of classifications for all the
59
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
60
training examples. This seems to be a nice goal to aim for, and we’ll soon
formalize this idea using the notion of functional margins.
For a different type of intuition, consider the following figure, in which x’s
represent positive training examples, o’s denote negative training examples,
a decision boundary (this is the line given by the equation
θ
T
x
= 0, and
is also called the
separating hyperplane
) is also shown, and three points
have also been labeled A, B and C.
B
A
C
Notice that the point A is very far from the decision boundary. If we are
asked to make a prediction for the value of
y
at A, it seems we should be
quite confident that
y
= 1 there.
Conversely, the point C is very close to
the decision boundary, and while it’s on the side of the decision boundary
on which we would predict
y
= 1, it seems likely that just a small change to
the decision boundary could easily have caused out prediction to be
y
= 0.
Hence, we’re much more confident about our prediction at A than at C. The
point B lies in-between these two cases, and more broadly, we see that if
a point is far from the separating hyperplane, then we may be significantly
more confident in our predictions. Again, informally we think it would be
nice if, given a training set, we manage to find a decision boundary that
allows us to make all correct and confident (meaning far from the decision
boundary) predictions on the training examples. We’ll formalize this later
using the notion of geometric margins.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
61
6.2
Notation (option reading)
To make our discussion of SVMs easier, we’ll first need to introduce a new
notation for talking about classification.
We will be considering a linear
classifier for a binary classification problem with labels
y
and features
x
.
From now, we’ll use
y
∈ {-
1
,
1
}
(instead of
{
0
,
1
}
) to denote the class labels.
Also, rather than parameterizing our linear classifier with the vector
θ
, we
will use parameters
w, b
, and write our classifier as
h
w,b
(
x
) =
g
(
w
T
x
+
b
)
.
Here,
g
(
z
) = 1 if
z
≥
0, and
g
(
z
) =
-
1 otherwise.
This “
w, b
” notation
allows us to explicitly treat the intercept term
b
separately from the other
parameters. (We also drop the convention we had previously of letting
x
0
= 1
be an extra coordinate in the input feature vector.) Thus,
b
takes the role of
what was previously
θ
0
, and
w
takes the role of [
θ
1
. . . θ
d
]
T
.
Note also that, from our definition of
g
above, our classifier will directly
predict either 1 or
-
1 (cf.
the perceptron algorithm), without first going
through the intermediate step of estimating
p
(
y
= 1) (which is what logistic
regression does).
6.3
Functional and geometric margins (op-
tion reading)
Let’s formalize the notions of the functional and geometric margins. Given a
training example (
x
(
i
)
, y
(
i
)
), we define the
functional margin
of (
w, b
) with
respect to the training example as
ˆ
γ
(
i
)
=
y
(
i
)
(
w
T
x
(
i
)
+
b
)
.
Note that if
y
(
i
)
= 1, then for the functional margin to be large (i.e., for
our prediction to be confident and correct), we need
w
T
x
(
i
)
+
b
to be a large
positive number.
Conversely, if
y
(
i
)
=
-
1, then for the functional margin
to be large, we need
w
T
x
(
i
)
+
b
to be a large negative number. Moreover, if
y
(
i
)
(
w
T
x
(
i
)
+
b
)
>
0, then our prediction on this example is correct. (Check
this yourself.) Hence, a large functional margin represents a confident and a
correct prediction.
For a linear classifier with the choice of
g
given above (taking values in
{-
1
,
1
}
), there’s one property of the functional margin that makes it not a
very good measure of confidence, however. Given our choice of
g
, we note that
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
62
if we replace
w
with 2
w
and
b
with 2
b
, then since
g
(
w
T
x
+
b
) =
g
(2
w
T
x
+2
b
),
this would not change
h
w,b
(
x
) at all. I.e.,
g
, and hence also
h
w,b
(
x
), depends
only on the sign, but not on the magnitude, of
w
T
x
+
b
. However, replacing
(
w, b
) with (2
w,
2
b
) also results in multiplying our functional margin by a
factor of 2. Thus, it seems that by exploiting our freedom to scale
w
and
b
,
we can make the functional margin arbitrarily large without really changing
anything meaningful.
Intuitively, it might therefore make sense to impose
some sort of normalization condition such as that
||
w
||
2
= 1; i.e., we might
replace (
w, b
) with (
w/
||
w
||
2
, b/
||
w
||
2
), and instead consider the functional
margin of (
w/
||
w
||
2
, b/
||
w
||
2
). We’ll come back to this later.
Given a training set
S
=
{
(
x
(
i
)
, y
(
i
)
);
i
= 1
, . . . , n
}
, we also define the
function margin of (
w, b
) with respect to
S
as the smallest of the functional
margins of the individual training examples. Denoted by ˆ
γ
, this can therefore
be written:
ˆ
γ
=
min
i
=1
,...,n
ˆ
γ
(
i
)
.
Next, let’s talk about
geometric margins
. Consider the picture below:
w
A
γ
B
(i)
The decision boundary corresponding to (
w, b
) is shown, along with the
vector
w
. Note that
w
is orthogonal (at 90
◦
) to the separating hyperplane.
(You should convince yourself that this must be the case.)
Consider the
point at A, which represents the input
x
(
i
)
of some training example with
label
y
(
i
)
= 1. Its distance to the decision boundary,
γ
(
i
)
, is given by the line
segment AB.
How can we find the value of
γ
(
i
)
? Well,
w/
||
w
||
is a unit-length vector
pointing in the same direction as
w
.
Since
A
represents
x
(
i
)
, we therefore
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
63
find that the point
B
is given by
x
(
i
)
-
γ
(
i
)
·
w/
||
w
||
. But this point lies on
the decision boundary, and all points
x
on the decision boundary satisfy the
equation
w
T
x
+
b
= 0. Hence,
w
T
x
(
i
)
-
γ
(
i
)
w
||
w
||
+
b
= 0
.
Solving for
γ
(
i
)
yields
γ
(
i
)
=
w
T
x
(
i
)
+
b
||
w
||
=
w
||
w
||
T
x
(
i
)
+
b
||
w
||
.
This was worked out for the case of a positive training example at A in the
figure, where being on the “positive” side of the decision boundary is good.
More generally, we define the geometric margin of (
w, b
) with respect to a
training example (
x
(
i
)
, y
(
i
)
) to be
γ
(
i
)
=
y
(
i
)
w
||
w
||
T
x
(
i
)
+
b
||
w
||
!
.
Note that if
||
w
||
= 1, then the functional margin equals the geometric
margin—this thus gives us a way of relating these two different notions of
margin. Also, the geometric margin is invariant to rescaling of the parame-
ters; i.e., if we replace
w
with 2
w
and
b
with 2
b
, then the geometric margin
does not change. This will in fact come in handy later. Specifically, because
of this invariance to the scaling of the parameters, when trying to fit
w
and
b
to training data, we can impose an arbitrary scaling constraint on
w
without
changing anything important; for instance, we can demand that
||
w
||
= 1, or
|
w
1
|
= 5, or
|
w
1
+
b
|
+
|
w
2
|
= 2, and any of these can be satisfied simply by
rescaling
w
and
b
.
Finally, given a training set
S
=
{
(
x
(
i
)
, y
(
i
)
);
i
= 1
, . . . , n
}
, we also define
the geometric margin of (
w, b
) with respect to
S
to be the smallest of the
geometric margins on the individual training examples:
γ
=
min
i
=1
,...,n
γ
(
i
)
.
6.4
The optimal margin classifier (option read-
ing)
Given a training set, it seems from our previous discussion that a natural
desideratum is to try to find a decision boundary that maximizes the (ge-
ometric) margin, since this would reflect a very confident set of predictions
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
64
on the training set and a good “fit” to the training data. Specifically, this
will result in a classifier that separates the positive and the negative training
examples with a “gap” (geometric margin).
For now, we will assume that we are given a training set that is linearly
separable; i.e., that it is possible to separate the positive and negative ex-
amples using some separating hyperplane.
How will we find the one that
achieves the maximum geometric margin? We can pose the following opti-
mization problem:
max
γ,w,b
γ
s.t.
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≥
γ,
i
= 1
, . . . , n
||
w
||
= 1
.
I.e., we want to maximize
γ
, subject to each training example having func-
tional margin at least
γ
. The
||
w
||
= 1 constraint moreover ensures that the
functional margin equals to the geometric margin, so we are also guaranteed
that all the geometric margins are at least
γ
. Thus, solving this problem will
result in (
w, b
) with the largest possible geometric margin with respect to the
training set.
If we could solve the optimization problem above, we’d be done. But the
“
||
w
||
= 1” constraint is a nasty (non-convex) one, and this problem certainly
isn’t in any format that we can plug into standard optimization software to
solve. So, let’s try transforming the problem into a nicer one. Consider:
max
ˆ
γ,w,b
ˆ
γ
||
w
||
s.t.
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≥
ˆ
γ,
i
= 1
, . . . , n
Here, we’re going to maximize ˆ
γ/
||
w
||
, subject to the functional margins all
being at least ˆ
γ
. Since the geometric and functional margins are related by
γ
= ˆ
γ/
||
w
|
, this will give us the answer we want. Moreover, we’ve gotten rid
of the constraint
||
w
||
= 1 that we didn’t like. The downside is that we now
have a nasty (again, non-convex) objective
ˆ
γ
||
w
||
function; and, we still don’t
have any off-the-shelf software that can solve this form of an optimization
problem.
Let’s keep going. Recall our earlier discussion that we can add an arbi-
trary scaling constraint on
w
and
b
without changing anything. This is the
key idea we’ll use now.
We will introduce the scaling constraint that the
functional margin of
w, b
with respect to the training set must be 1:
ˆ
γ
= 1
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
65
Since multiplying
w
and
b
by some constant results in the functional margin
being multiplied by that same constant, this is indeed a scaling constraint,
and can be satisfied by rescaling
w, b
. Plugging this into our problem above,
and noting that maximizing ˆ
γ/
||
w
||
= 1
/
||
w
||
is the same thing as minimizing
||
w
||
2
, we now have the following optimization problem:
min
w,b
1
2
||
w
||
2
s.t.
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≥
1
,
i
= 1
, . . . , n
We’ve now transformed the problem into a form that can be efficiently
solved. The above is an optimization problem with a convex quadratic ob-
jective and only linear constraints. Its solution gives us the
optimal mar-
gin classifier
. This optimization problem can be solved using commercial
quadratic programming (QP) code.
1
While we could call the problem solved here, what we will instead do is
make a digression to talk about Lagrange duality. This will lead us to our
optimization problem’s dual form, which will play a key role in allowing us to
use kernels to get optimal margin classifiers to work efficiently in very high
dimensional spaces. The dual form will also allow us to derive an efficient
algorithm for solving the above optimization problem that will typically do
much better than generic QP software.
6.5
Lagrange duality (optional reading)
Let’s temporarily put aside SVMs and maximum margin classifiers, and talk
about solving constrained optimization problems.
Consider a problem of the following form:
min
w
f
(
w
)
s.t.
h
i
(
w
) = 0
,
i
= 1
, . . . , l.
Some of you may recall how the method of Lagrange multipliers can be used
to solve it. (Don’t worry if you haven’t seen it before.) In this method, we
define the
Lagrangian
to be
L
(
w, β
) =
f
(
w
) +
l
X
i
=1
β
i
h
i
(
w
)
1
You may be familiar with linear programming, which solves optimization problems
that have linear objectives and linear constraints.
QP software is also widely available,
which allows convex quadratic objectives and linear constraints.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
66
Here, the
β
i
’s are called the
Lagrange multipliers
.
We would then find
and set
L
’s partial derivatives to zero:
∂
L
∂w
i
= 0;
∂
L
∂β
i
= 0
,
and solve for
w
and
β
.
In this section, we will generalize this to constrained optimization prob-
lems in which we may have inequality as well as equality constraints. Due to
time constraints, we won’t really be able to do the theory of Lagrange duality
justice in this class,
2
but we will give the main ideas and results, which we
will then apply to our optimal margin classifier’s optimization problem.
Consider the following, which we’ll call the
primal
optimization problem:
min
w
f
(
w
)
s.t.
g
i
(
w
)
≤
0
,
i
= 1
, . . . , k
h
i
(
w
) = 0
,
i
= 1
, . . . , l.
To solve it, we start by defining the
generalized Lagrangian
L
(
w, α, β
) =
f
(
w
) +
k
X
i
=1
α
i
g
i
(
w
) +
l
X
i
=1
β
i
h
i
(
w
)
.
Here, the
α
i
’s and
β
i
’s are the Lagrange multipliers. Consider the quantity
θ
P
(
w
) =
max
α,β
:
α
i
≥
0
L
(
w, α, β
)
.
Here, the “
P
” subscript stands for “primal.”
Let some
w
be given.
If
w
violates any of the primal constraints (i.e., if either
g
i
(
w
)
>
0 or
h
i
(
w
)
6
= 0
for some
i
), then you should be able to verify that
θ
P
(
w
)
=
max
α,β
:
α
i
≥
0
f
(
w
) +
k
X
i
=1
α
i
g
i
(
w
) +
l
X
i
=1
β
i
h
i
(
w
)
(6.1)
=
∞
.
(6.2)
Conversely, if the constraints are indeed satisfied for a particular value of
w
,
then
θ
P
(
w
) =
f
(
w
). Hence,
θ
P
(
w
) =
f
(
w
)
if
w
satisfies primal constraints
∞
otherwise
.
2
Readers interested in learning more about this topic are encouraged to read, e.g., R.
T. Rockarfeller (1970), Convex Analysis, Princeton University Press.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
67
Thus,
θ
P
takes the same value as the objective in our problem for all val-
ues of
w
that satisfies the primal constraints, and is positive infinity if the
constraints are violated. Hence, if we consider the minimization problem
min
w
θ
P
(
w
) = min
w
max
α,β
:
α
i
≥
0
L
(
w, α, β
)
,
we see that it is the same problem (i.e., and has the same solutions as) our
original, primal problem. For later use, we also define the optimal value of
the objective to be
p
*
= min
w
θ
P
(
w
); we call this the
value
of the primal
problem.
Now, let’s look at a slightly different problem. We define
θ
D
(
α, β
) = min
w
L
(
w, α, β
)
.
Here, the “
D
” subscript stands for “dual.”
Note also that whereas in the
definition of
θ
P
we were optimizing (maximizing) with respect to
α, β
, here
we are minimizing with respect to
w
.
We can now pose the
dual
optimization problem:
max
α,β
:
α
i
≥
0
θ
D
(
α, β
) =
max
α,β
:
α
i
≥
0
min
w
L
(
w, α, β
)
.
This is exactly the same as our primal problem shown above, except that the
order of the “max” and the “min” are now exchanged. We also define the
optimal value of the dual problem’s objective to be
d
*
= max
α,β
:
α
i
≥
0
θ
D
(
w
).
How are the primal and the dual problems related? It can easily be shown
that
d
*
=
max
α,β
:
α
i
≥
0
min
w
L
(
w, α, β
)
≤
min
w
max
α,β
:
α
i
≥
0
L
(
w, α, β
) =
p
*
.
(You should convince yourself of this; this follows from the “max min” of a
function always being less than or equal to the “min max.”) However, under
certain conditions, we will have
d
*
=
p
*
,
so that we can solve the dual problem in lieu of the primal problem. Let’s
see what these conditions are.
Suppose
f
and the
g
i
’s are convex,
3
and the
h
i
’s are affine.
4
Suppose
further that the constraints
g
i
are (strictly) feasible; this means that there
exists some
w
so that
g
i
(
w
)
<
0 for all
i
.
3
When
f
has a Hessian, then it is convex if and only if the Hessian is positive semi-
definite. For instance,
f
(
w
) =
w
T
w
is convex; similarly, all linear (and affine) functions
are also convex.
(A function
f
can also be convex without being differentiable, but we
won’t need those more general definitions of convexity here.)
4
I.e., there exists
a
i
,
b
i
, so that
h
i
(
w
) =
a
T
i
w
+
b
i
. “Affine” means the same thing as
linear, except that we also allow the extra intercept term
b
i
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
68
Under our above assumptions, there must exist
w
*
, α
*
, β
*
so that
w
*
is the
solution to the primal problem,
α
*
, β
*
are the solution to the dual problem,
and moreover
p
*
=
d
*
=
L
(
w
*
, α
*
, β
*
). Moreover,
w
*
, α
*
and
β
*
satisfy the
Karush-Kuhn-Tucker (KKT) conditions
, which are as follows:
∂
∂w
i
L
(
w
*
, α
*
, β
*
)
=
0
,
i
= 1
, . . . , d
(6.3)
∂
∂β
i
L
(
w
*
, α
*
, β
*
)
=
0
,
i
= 1
, . . . , l
(6.4)
α
*
i
g
i
(
w
*
)
=
0
,
i
= 1
, . . . , k
(6.5)
g
i
(
w
*
)
≤
0
,
i
= 1
, . . . , k
(6.6)
α
*
≥
0
,
i
= 1
, . . . , k
(6.7)
Moreover, if some
w
*
, α
*
, β
*
satisfy the KKT conditions, then it is also a solution to t
he primal and dual
problems.
We draw attention to Equation (6.5), which is called the KKT
dual
complementarity
condition.
Specifically, it implies that if
α
*
i
>
0, then
g
i
(
w
*
) = 0. (I.e., the “
g
i
(
w
)
≤
0” constraint is
active
, meaning it holds with
equality rather than with inequality.) Later on, this will be key for showing
that the SVM has only a small number of “support vectors”; the KKT dual
complementarity condition will also give us our convergence test when we
talk about the SMO algorithm.
6.6
Optimal margin classifiers: the dual form
(option reading)
Note:
The equivalence of optimization problem
(6.8)
and the optimization
problem
(6.12)
, and the relationship between the primary and dual variables
in equation
(6.10)
are the most important take home messages of this section.
Previously, we posed the following (primal) optimization problem for find-
ing the optimal margin classifier:
min
w,b
1
2
||
w
||
2
(6.8)
s.t.
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≥
1
,
i
= 1
, . . . , n
We can write the constraints as
g
i
(
w
) =
-
y
(
i
)
(
w
T
x
(
i
)
+
b
) + 1
≤
0
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
69
We have one such constraint for each training example. Note that from the
KKT dual complementarity condition, we will have
α
i
>
0 only for the train-
ing examples that have functional margin exactly equal to one (i.e., the ones
corresponding to constraints that hold with equality,
g
i
(
w
) = 0). Consider
the figure below, in which a maximum margin separating hyperplane is shown
by the solid line.
The points with the smallest margins are exactly the ones closest to the
decision boundary; here, these are the three points (one negative and two pos-
itive examples) that lie on the dashed lines parallel to the decision boundary.
Thus, only three of the
α
i
’s—namely, the ones corresponding to these three
training examples—will be non-zero at the optimal solution to our optimiza-
tion problem.
These three points are called the
support vectors
in this
problem. The fact that the number of support vectors can be much smaller
than the size the training set will be useful later.
Let’s move on. Looking ahead, as we develop the dual form of the prob-
lem, one key idea to watch out for is that we’ll try to write our algorithm
in terms of only the inner product
h
x
(
i
)
, x
(
j
)
i
(think of this as (
x
(
i
)
)
T
x
(
j
)
)
between points in the input feature space. The fact that we can express our
algorithm in terms of these inner products will be key when we apply the
kernel trick.
When we construct the Lagrangian for our optimization problem we have:
L
(
w, b, α
) =
1
2
||
w
||
2
-
n
X
i
=1
α
i
y
(
i
)
(
w
T
x
(
i
)
+
b
)
-
1
.
(6.9)
Note that there’re only “
α
i
” but no “
β
i
” Lagrange multipliers, since the
problem has only inequality constraints.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
70
Let’s find the dual form of the problem.
To do so, we need to first
minimize
L
(
w, b, α
) with respect to
w
and
b
(for fixed
α
), to get
θ
D
, which
we’ll do by setting the derivatives of
L
with respect to
w
and
b
to zero. We
have:
∇
w
L
(
w, b, α
) =
w
-
n
X
i
=1
α
i
y
(
i
)
x
(
i
)
= 0
This implies that
w
=
n
X
i
=1
α
i
y
(
i
)
x
(
i
)
.
(6.10)
As for the derivative with respect to
b
, we obtain
∂
∂b
L
(
w, b, α
) =
n
X
i
=1
α
i
y
(
i
)
= 0
.
(6.11)
If we take the definition of
w
in Equation (6.10) and plug that back into
the Lagrangian (Equation 6.9), and simplify, we get
L
(
w, b, α
) =
n
X
i
=1
α
i
-
1
2
n
X
i,j
=1
y
(
i
)
y
(
j
)
α
i
α
j
(
x
(
i
)
)
T
x
(
j
)
-
b
n
X
i
=1
α
i
y
(
i
)
.
But from Equation (6.11), the last term must be zero, so we obtain
L
(
w, b, α
) =
n
X
i
=1
α
i
-
1
2
n
X
i,j
=1
y
(
i
)
y
(
j
)
α
i
α
j
(
x
(
i
)
)
T
x
(
j
)
.
Recall that we got to the equation above by minimizing
L
with respect to
w
and
b
. Putting this together with the constraints
α
i
≥
0 (that we always
had) and the constraint (6.11), we obtain the following dual optimization
problem:
max
α
W
(
α
) =
n
X
i
=1
α
i
-
1
2
n
X
i,j
=1
y
(
i
)
y
(
j
)
α
i
α
j
h
x
(
i
)
, x
(
j
)
i
.
(6.12)
s.t.
α
i
≥
0
,
i
= 1
, . . . , n
n
X
i
=1
α
i
y
(
i
)
= 0
,
You should also be able to verify that the conditions required for
p
*
=
d
*
and the KKT conditions (Equations 6.3–6.7) to hold are indeed satisfied in
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
71
our optimization problem.
Hence, we can solve the dual in lieu of solving
the primal problem.
Specifically, in the dual problem above, we have a
maximization problem in which the parameters are the
α
i
’s. We’ll talk later
about the specific algorithm that we’re going to use to solve the dual problem,
but if we are indeed able to solve it (i.e., find the
α
’s that maximize
W
(
α
)
subject to the constraints), then we can use Equation (6.10) to go back and
find the optimal
w
’s as a function of the
α
’s. Having found
w
*
, by considering
the primal problem, it is also straightforward to find the optimal value for
the intercept term
b
as
b
*
=
-
max
i
:
y
(
i
)
=
-
1
w
*
T
x
(
i
)
+ min
i
:
y
(
i
)
=1
w
*
T
x
(
i
)
2
.
(6.13)
(Check for yourself that this is correct.)
Before moving on, let’s also take a more careful look at Equation (6.10),
which gives the optimal value of
w
in terms of (the optimal value of)
α
.
Suppose we’ve fit our model’s parameters to a training set, and now wish to
make a prediction at a new point input
x
. We would then calculate
w
T
x
+
b
,
and predict
y
= 1 if and only if this quantity is bigger than zero.
But
using (6.10), this quantity can also be written:
w
T
x
+
b
=
n
X
i
=1
α
i
y
(
i
)
x
(
i
)
!
T
x
+
b
(6.14)
=
n
X
i
=1
α
i
y
(
i
)
h
x
(
i
)
, x
i
+
b.
(6.15)
Hence, if we’ve found the
α
i
’s, in order to make a prediction, we have to
calculate a quantity that depends only on the inner product between
x
and
the points in the training set. Moreover, we saw earlier that the
α
i
’s will all
be zero except for the support vectors. Thus, many of the terms in the sum
above will be zero, and we really need to find only the inner products between
x
and the support vectors (of which there is often only a small number) in
order calculate (6.15) and make our prediction.
By examining the dual form of the optimization problem, we gained sig-
nificant insight into the structure of the problem, and were also able to write
the entire algorithm in terms of only inner products between input feature
vectors. In the next section, we will exploit this property to apply the ker-
nels to our classification problem. The resulting algorithm,
support vector
machines
, will be able to efficiently learn in very high dimensional spaces.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
72
6.7
Regularization and the non-separable case
(optional reading)
The derivation of the SVM as presented so far assumed that the data is
linearly separable. While mapping data to a high dimensional feature space
via
φ
does generally increase the likelihood that the data is separable, we
can’t guarantee that it always will be so. Also, in some cases it is not clear
that finding a separating hyperplane is exactly what we’d want to do, since
that might be susceptible to outliers.
For instance, the left figure below
shows an optimal margin classifier, and when a single outlier is added in the
upper-left region (right figure), it causes the decision boundary to make a
dramatic swing, and the resulting classifier has a much smaller margin.
To make the algorithm work for non-linearly separable datasets as well
as be less sensitive to outliers, we reformulate our optimization (using
‘
1
regularization
) as follows:
min
γ,w,b
1
2
||
w
||
2
+
C
n
X
i
=1
ξ
i
s.t.
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≥
1
-
ξ
i
,
i
= 1
, . . . , n
ξ
i
≥
0
,
i
= 1
, . . . , n.
Thus, examples are now permitted to have (functional) margin less than 1,
and if an example has functional margin 1
-
ξ
i
(with
ξ >
0), we would pay
a cost of the objective function being increased by
Cξ
i
. The parameter
C
controls the relative weighting between the twin goals of making the
||
w
||
2
small (which we saw earlier makes the margin large) and of ensuring that
most examples have functional margin at least 1.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
73
As before, we can form the Lagrangian:
L
(
w, b, ξ, α, r
) =
1
2
w
T
w
+
C
n
X
i
=1
ξ
i
-
n
X
i
=1
α
i
y
(
i
)
(
x
T
w
+
b
)
-
1 +
ξ
i
-
n
X
i
=1
r
i
ξ
i
.
Here, the
α
i
’s and
r
i
’s are our Lagrange multipliers (constrained to be
≥
0).
We won’t go through the derivation of the dual again in detail, but after
setting the derivatives with respect to
w
and
b
to zero as before, substituting
them back in, and simplifying, we obtain the following dual form of the
problem:
max
α
W
(
α
) =
n
X
i
=1
α
i
-
1
2
n
X
i,j
=1
y
(
i
)
y
(
j
)
α
i
α
j
h
x
(
i
)
, x
(
j
)
i
s.t.
0
≤
α
i
≤
C,
i
= 1
, . . . , n
n
X
i
=1
α
i
y
(
i
)
= 0
,
As before, we also have that
w
can be expressed in terms of the
α
i
’s as
given in Equation (6.10), so that after solving the dual problem, we can con-
tinue to use Equation (6.15) to make our predictions. Note that, somewhat
surprisingly, in adding
‘
1
regularization, the only change to the dual prob-
lem is that what was originally a constraint that 0
≤
α
i
has now become
0
≤
α
i
≤
C
. The calculation for
b
*
also has to be modified (Equation 6.13 is
no longer valid); see the comments in the next section/Platt’s paper.
Also, the KKT dual-complementarity conditions (which in the next sec-
tion will be useful for testing for the convergence of the SMO algorithm)
are:
α
i
= 0
⇒
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≥
1
(6.16)
α
i
=
C
⇒
y
(
i
)
(
w
T
x
(
i
)
+
b
)
≤
1
(6.17)
0
< α
i
< C
⇒
y
(
i
)
(
w
T
x
(
i
)
+
b
) = 1
.
(6.18)
Now, all that remains is to give an algorithm for actually solving the dual
problem, which we will do in the next section.
6.8
The SMO algorithm (optional reading)
The SMO (sequential minimal optimization) algorithm, due to John Platt,
gives an efficient way of solving the dual problem arising from the derivation
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
74
of the SVM. Partly to motivate the SMO algorithm, and partly because it’s
interesting in its own right, let’s first take another digression to talk about
the coordinate ascent algorithm.
6.8.1
Coordinate ascent
Consider trying to solve the unconstrained optimization problem
max
α
W
(
α
1
, α
2
, . . . , α
n
)
.
Here, we think of
W
as just some function of the parameters
α
i
’s, and for now
ignore any relationship between this problem and SVMs. We’ve already seen
two optimization algorithms, gradient ascent and Newton’s method.
The
new algorithm we’re going to consider here is called
coordinate ascent
:
Loop until convergence:
{
For
i
= 1
, . . . , n
,
{
α
i
:= arg max
ˆ
α
i
W
(
α
1
, . . . , α
i
-
1
,
ˆ
α
i
, α
i
+1
, . . . , α
n
).
}
}
Thus, in the innermost loop of this algorithm, we will hold all the variables
except for some
α
i
fixed, and reoptimize
W
with respect to just the parameter
α
i
. In the version of this method presented here, the inner-loop reoptimizes
the variables in order
α
1
, α
2
, . . . , α
n
, α
1
, α
2
, . . .
. (A more sophisticated version
might choose other orderings; for instance, we may choose the next variable
to update according to which one we expect to allow us to make the largest
increase in
W
(
α
).)
When the function
W
happens to be of such a form that the “arg max”
in the inner loop can be performed efficiently, then coordinate ascent can be
a fairly efficient algorithm. Here’s a picture of coordinate ascent in action:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
75
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
The ellipses in the figure are the contours of a quadratic function that
we want to optimize. Coordinate ascent was initialized at (2
,
-
2), and also
plotted in the figure is the path that it took on its way to the global maximum.
Notice that on each step, coordinate ascent takes a step that’s parallel to one
of the axes, since only one variable is being optimized at a time.
6.8.2
SMO
We close off the discussion of SVMs by sketching the derivation of the SMO
algorithm.
Here’s the (dual) optimization problem that we want to solve:
max
α
W
(
α
) =
n
X
i
=1
α
i
-
1
2
n
X
i,j
=1
y
(
i
)
y
(
j
)
α
i
α
j
h
x
(
i
)
, x
(
j
)
i
.
(6.19)
s.t.
0
≤
α
i
≤
C,
i
= 1
, . . . , n
(6.20)
n
X
i
=1
α
i
y
(
i
)
= 0
.
(6.21)
Let’s say we have set of
α
i
’s that satisfy the constraints (6.20-6.21). Now,
suppose we want to hold
α
2
, . . . , α
n
fixed, and take a coordinate ascent step
and reoptimize the objective with respect to
α
1
. Can we make any progress?
The answer is no, because the constraint (6.21) ensures that
α
1
y
(1)
=
-
n
X
i
=2
α
i
y
(
i
)
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
76
Or, by multiplying both sides by
y
(1)
, we equivalently have
α
1
=
-
y
(1)
n
X
i
=2
α
i
y
(
i
)
.
(This step used the fact that
y
(1)
∈ {-
1
,
1
}
, and hence (
y
(1)
)
2
= 1.) Hence,
α
1
is exactly determined by the other
α
i
’s, and if we were to hold
α
2
, . . . , α
n
fixed, then we can’t make any change to
α
1
without violating the con-
straint (6.21) in the optimization problem.
Thus, if we want to update some subject of the
α
i
’s, we must update at
least two of them simultaneously in order to keep satisfying the constraints.
This motivates the SMO algorithm, which simply does the following:
Repeat till convergence
{
1. Select some pair
α
i
and
α
j
to update next (using a heuristic that
tries to pick the two that will allow us to make the biggest progress
towards the global maximum).
2. Reoptimize
W
(
α
) with respect to
α
i
and
α
j
, while holding all the
other
α
k
’s (
k
6
=
i, j
) fixed.
}
To test for convergence of this algorithm, we can check whether the KKT
conditions (Equations 6.16-6.18) are satisfied to within some
t
ol
. Here,
t
ol
is
the convergence tolerance parameter, and is typically set to around 0.01 to
0.001. (See the paper and pseudocode for details.)
The key reason that SMO is an efficient algorithm is that the update to
α
i
,
α
j
can be computed very efficiently. Let’s now briefly sketch the main
ideas for deriving the efficient update.
Let’s say we currently have some setting of the
α
i
’s that satisfy the con-
straints (6.20-6.21), and suppose we’ve decided to hold
α
3
, . . . , α
n
fixed, and
want to reoptimize
W
(
α
1
, α
2
, . . . , α
n
) with respect to
α
1
and
α
2
(subject to
the constraints). From (6.21), we require that
α
1
y
(1)
+
α
2
y
(2)
=
-
n
X
i
=3
α
i
y
(
i
)
.
Since the right hand side is fixed (as we’ve fixed
α
3
, . . . α
n
), we can just let
it be denoted by some constant
ζ
:
α
1
y
(1)
+
α
2
y
(2)
=
ζ.
(6.22)
We can thus picture the constraints on
α
1
and
α
2
as follows:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
77
α
2
α
1
α
1
α
2
C
C
(1)
+
(2)
y
y
=ζ
H
L
From the constraints (6.20), we know that
α
1
and
α
2
must lie within the box
[0
, C
]
×
[0
, C
] shown. Also plotted is the line
α
1
y
(1)
+
α
2
y
(2)
=
ζ
, on which we
know
α
1
and
α
2
must lie. Note also that, from these constraints, we know
L
≤
α
2
≤
H
; otherwise, (
α
1
, α
2
) can’t simultaneously satisfy both the box
and the straight line constraint. In this example,
L
= 0. But depending on
what the line
α
1
y
(1)
+
α
2
y
(2)
=
ζ
looks like, this won’t always necessarily be
the case; but more generally, there will be some lower-bound
L
and some
upper-bound
H
on the permissible values for
α
2
that will ensure that
α
1
,
α
2
lie within the box [0
, C
]
×
[0
, C
].
Using Equation (6.22), we can also write
α
1
as a function of
α
2
:
α
1
= (
ζ
-
α
2
y
(2)
)
y
(1)
.
(Check this derivation yourself; we again used the fact that
y
(1)
∈ {-
1
,
1
}
so
that (
y
(1)
)
2
= 1.) Hence, the objective
W
(
α
) can be written
W
(
α
1
, α
2
, . . . , α
n
) =
W
((
ζ
-
α
2
y
(2)
)
y
(1)
, α
2
, . . . , α
n
)
.
Treating
α
3
, . . . , α
n
as constants, you should be able to verify that this is
just some quadratic function in
α
2
.
I.e., this can also be expressed in the
form
aα
2
2
+
bα
2
+
c
for some appropriate
a
,
b
, and
c
. If we ignore the “box”
constraints (6.20) (or, equivalently, that
L
≤
α
2
≤
H
), then we can easily
maximize this quadratic function by setting its derivative to zero and solving.
We’ll let
α
n
ew,unclipped
2
denote the resulting value of
α
2
. You should also be
able to convince yourself that if we had instead wanted to maximize
W
with
respect to
α
2
but subject to the box constraint, then we can find the resulting
value optimal simply by taking
α
n
ew,unclipped
2
and “clipping” it to lie in the
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
78
[
L, H
] interval, to get
α
n
ew
2
=
H
if
α
n
ew,unclipped
2
> H
α
n
ew,unclipped
2
if
L
≤
α
n
ew,unclipped
2
≤
H
L
if
α
n
ew,unclipped
2
< L
Finally, having found the
α
n
ew
2
, we can use Equation (6.22) to go back and
find the optimal value of
α
n
ew
1
.
There’re a couple more details that are quite easy but that we’ll leave you
to read about yourself in Platt’s paper: One is the choice of the heuristics
used to select the next
α
i
,
α
j
to update; the other is how to update
b
as the
SMO algorithm is run.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Part II
Deep learning
79
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 7
Deep learning
We now begin our study of deep learning. In this set of notes, we give an
overview of neural networks, discuss vectorization and discuss training neural
networks with backpropagation.
7.1
Supervised learning with non-linear mod-
els
In the supervised learning setting (predicting
y
from the input
x
), suppose
our model/hypothesis is
h
θ
(
x
). In the past lectures, we have considered the
cases when
h
θ
(
x
) =
θ
>
x
(in linear regression or logistic regression) or
h
θ
(
x
) =
θ
>
φ
(
x
) (where
φ
(
x
) is the feature map). A commonality of these two models
is that they are linear in the parameters
θ
. Next we will consider learning
general family of models that are
non-linear in both
the parameters
θ
and the inputs
x
. The most common non-linear models are neural networks,
which we will define staring from the next section. For this section, it suffices
to think
h
θ
(
x
) as an abstract non-linear model.
1
Suppose
{
(
x
(
i
)
, y
(
i
)
)
}
n
i
=1
are the training examples. For simplicity, we start
with the case where
y
(
i
)
∈
R
and
h
θ
(
x
)
∈
R
.
Cost/loss function.
We define the least square cost function for the
i
-th
example (
x
(
i
)
, y
(
i
)
) as
J
(
i
)
(
θ
) =
1
2
(
h
θ
(
x
(
i
)
)
-
y
(
i
)
)
2
(7.1)
1
If a concrete example is helpful, perhaps think about the model
h
θ
(
x
) =
θ
2
1
x
2
1
+
θ
2
2
x
2
2
+
· · ·
+
θ
2
d
x
2
d
in this subsection, even though it’s not a neural network.
80
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
81
and define the mean-square cost function for the dataset as
J
(
θ
) =
1
n
n
X
i
=1
J
(
i
)
(
θ
)
(7.2)
which is same as in linear regression except that we introduce a constant
1
/n
in front of the cost function to be consistent with the convention. Note
that multiplying the cost function with a scalar will not change the local
minima or global minima of the cost function. Also note that the underlying
parameterization for
h
θ
(
x
) is different from the case of linear regression,
even though the form of the cost function is the same mean-squared loss.
Throughout the notes, we use the words “loss” and “cost” interchangeably.
Optimizers (SGD).
Commonly, people use gradient descent (GD), stochas-
tic gradient (SGD), or their variants to optimize the loss function
J
(
θ
). GD’s
update rule can be written as
2
θ
:=
θ
-
α
∇
θ
J
(
θ
)
(7.3)
where
α >
0 is often referred to as the learning rate or step size. Next, we
introduce a version of the SGD (Algorithm 1), which is lightly different from
that in the first lecture notes.
Algorithm 1
Stochastic Gradient Descent
1:
Hyperparameter: learning rate
α
, number of total iteration
n
iter
.
2:
Initialize
θ
randomly.
3:
for
i
= 1 to
n
iter
do
4:
Sample
j
uniformly from
{
1
, . . . , n
}
, and update
θ
by
θ
:=
θ
-
α
∇
θ
J
(
j
)
(
θ
)
(7.4)
Oftentimes computing the gradient of
B
examples simultaneously for the
parameter
θ
can be faster than computing
B
gradients separately due to
hardware parallelization.
Therefore, a mini-batch version of SGD is most
2
Recall that, as defined in the previous lecture notes, we use the notation “
a
:=
b
” to
denote an operation (in a computer program) in which we
set
the value of a variable
a
to
be equal to the value of
b
. In other words, this operation overwrites
a
with the value of
b
. In contrast, we will write “
a
=
b
” when we are asserting a statement of fact, that the
value of
a
is equal to the value of
b
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
82
commonly used in deep learning, as shown in Algorithm 2. There are also
other variants of the SGD or mini-batch SGD with slightly different sampling
schemes.
Algorithm 2
Mini-batch Stochastic Gradient Descent
1:
Hyperparameters: learning rate
α
, batch size
B
, # iterations
n
iter
.
2:
Initialize
θ
randomly
3:
for
i
= 1 to
n
iter
do
4:
Sample
B
examples
j
1
, . . . , j
B
(without replacement) uniformly from
{
1
, . . . , n
}
, and update
θ
by
θ
:=
θ
-
α
B
B
X
k
=1
∇
θ
J
(
j
k
)
(
θ
)
(7.5)
With these generic algorithms, a typical deep learning model is learned
with the following steps. 1. Define a neural network parametrization
h
θ
(
x
),
which we will introduce in Section 7.2, and 2.
write the backpropagation
algorithm to compute the gradient of the loss function
J
(
j
)
(
θ
) efficiently,
which will be covered in Section 7.3, and 3. run SGD or mini-batch SGD (or
other gradient-based optimizers) with the loss function
J
(
θ
).
7.2
Neural networks
Neural networks refer to broad type of non-linear models/parametrizations
h
θ
(
x
) that involve combinations of matrix multiplications and other entry-
wise non-linear operations. We will start small and slowly build up a neural
network, step by step.
A Neural Network with a Single Neuron.
Recall the housing price
prediction problem from before:
given the size of the house, we want to
predict the price. We will use it as a running example in this subsection.
Previously, we fit a straight line to the graph of size vs. housing price.
Now, instead of fitting a straight line, we wish to prevent negative housing
prices by setting the absolute minimum price as zero. This produces a “kink”
in the graph as shown in Figure 7.1. How do we represent such a function
with a single kink as
h
θ
(
x
) with unknown parameter? (After doing so, we
can invoke the machinery in Section 7.1.)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
83
We define a parameterized function
h
θ
(
x
) with input
x
, parameterized by
θ
, which outputs the price of the house
y
. Formally,
h
θ
:
x
→
y
. Perhaps
one of the simplest parametrization would be
h
θ
(
x
) = max(
wx
+
b,
0)
,
where
θ
= (
w, b
)
∈
R
2
(7.6)
Here
h
θ
(
x
) returns a single value: (
wx
+
b
) or zero, whichever is greater. In
the context of neural networks, the function max
{
t,
0
}
is called a ReLU (pro-
nounced “ray-lu”), or rectified linear unit, and often denoted by ReLU(
t
)
,
max
{
t,
0
}
.
Generally, a one-dimensional non-linear function that maps
R
to
R
such as
ReLU is often referred to as an
activation function
. The model
h
θ
(
x
) is said
to have a single neuron partly because it has a single non-linear activation
function. (We will discuss more about why a non-linear activation is called
neuron.)
When the input
x
∈
R
d
has multiple dimensions, a neural network with
a single neuron can be written as
h
θ
(
x
) = ReLU(
w
>
x
+
b
)
,
where
w
∈
R
d
,
b
∈
R
, and
θ
= (
w, b
)
(7.7)
The term
b
is often referred to as the “bias”, and the vector
w
is referred
to as the weight vector. Such a neural network has 1 layer. (We will define
what multiple layers mean in the sequel.)
Stacking Neurons.
A more complex neural network may take the single
neuron described above and “stack” them together such that one neuron
passes its output as input into the next neuron, resulting in a more complex
function.
Let us now deepen the housing prediction example. In addition to the size
of the house, suppose that you know the number of bedrooms, the zip code
and the wealth of the neighborhood. Building neural networks is analogous
to Lego bricks: you take individual bricks and stack them together to build
complex structures. The same applies to neural networks: we take individual
neurons and stack them together to create complex neural networks.
Given these features (size, number of bedrooms, zip code, and wealth),
we might then decide that the price of the house depends on the maximum
family size it can accommodate. Suppose the family size is a function of the
size of the house and number of bedrooms (see Figure 7.2).
The zip code
may provide additional information such as how walkable the neighborhood
is (i.e., can you walk to the grocery store or do you need to drive everywhere).
Combining the zip code with the wealth of the neighborhood may predict
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
84
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
0
100
200
300
400
500
600
700
800
900
1000
housing prices
square feet
price (in $1000)
Figure 7.1: Housing prices with a “kink” in the graph.
the quality of the local elementary school. Given these three derived features
(family size, walkable, school quality), we may conclude that the price of the
home ultimately depends on these three features.
Family Size
School Quality
Walkable
Size
# Bedrooms
Zip Code
Wealth
Price
y
Figure 7.2: Diagram of a small neural network for predicting housing prices.
Formally,
the input to a neural network is a set of input features
x
1
, x
2
, x
3
, x
4
. We denote the intermediate variables for “family size”, “walk-
able”, and “school quality” by
a
1
, a
2
, a
3
(these
a
i
’s are often referred to as
“hidden units” or “hidden neurons”). We represent each of the
a
i
’s as a neu-
ral network with a single neuron with a subset of
x
1
, . . . , x
4
as inputs. Then
as in Figure 7.1, we will have the parameterization:
a
1
= ReLU(
θ
1
x
1
+
θ
2
x
2
+
θ
3
)
a
2
= ReLU(
θ
4
x
3
+
θ
5
)
a
3
= ReLU(
θ
6
x
3
+
θ
7
x
4
+
θ
8
)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
85
where (
θ
1
,
· · ·
, θ
8
) are parameters. Now we represent the final output
h
θ
(
x
)
as another linear function with
a
1
, a
2
, a
3
as inputs, and we get
3
h
θ
(
x
) =
θ
9
a
1
+
θ
10
a
2
+
θ
11
a
3
+
θ
12
(7.8)
where
θ
contains all the parameters (
θ
1
,
· · ·
, θ
12
).
Now we represent the output as a quite complex function of
x
with pa-
rameters
θ
. Then you can use this parametrization
h
θ
with the machinery of
Section 7.1 to learn the parameters
θ
.
Inspiration from Biological Neural Networks.
As the name suggests,
artificial neural networks were inspired by biological neural networks. The
hidden units
a
1
, . . . , a
m
correspond to the neurons in a biological neural net-
work, and the parameters
θ
i
’s correspond to the synapses.
However, it’s
unclear how similar the modern deep artificial neural networks are to the bi-
ological ones. For example, perhaps not many neuroscientists think biological
neural networks could have 1000 layers, while some modern artificial neural
networks do (we will elaborate more on the notion of layers.) Moreover, it’s
an open question whether human brains update their neural networks in a
way similar to the way that computer scientists learn artificial neural net-
works (using backpropagation, which we will introduce in the next section.).
Two-layer Fully-Connected Neural Networks.
We constructed the
neural network in equation (7.8) using a significant amount of prior knowl-
edge/belief about how the “family size”, “walkable”, and “school quality” are
determined by the inputs. We implicitly assumed that we know the family
size is an important quantity to look at and that it can be determined by
only the “size” and “# bedrooms”.
Such a prior knowledge might not be
available for other applications. It would be more flexible and general to have
a generic parameterization. A simple way would be to write the intermediate
variable
a
1
as a function of all
x
1
, . . . , x
4
:
a
1
= ReLU(
w
>
1
x
+
b
1
)
,
where
w
1
∈
R
4
and
b
1
∈
R
(7.9)
a
2
= ReLU(
w
>
2
x
+
b
2
)
,
where
w
2
∈
R
4
and
b
2
∈
R
a
3
= ReLU(
w
>
3
x
+
b
3
)
,
where
w
3
∈
R
4
and
b
3
∈
R
We still define
h
θ
(
x
) using equation (7.8) with
a
1
, a
2
, a
3
being defined
as above. Thus we have a so-called
fully-connected neural network
as
3
Typically, for multi-layer neural network, at the end, near the output, we don’t apply
ReLU, especially when the output is not necessarily a positive number.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
86
Figure 7.3: Diagram of a two-layer fully connected neural network.
Each
edge from node
x
i
to node
a
j
indicates that
a
j
depends on
x
i
. The edge from
x
i
to
a
j
is associated with the weight (
w
[1]
j
)
i
which denotes the
i
-th coordinate
of the vector
w
[1]
j
. The activation
a
j
can be computed by taking the ReLUof
the weighted sum of
x
i
’s with the weights being the weights associated with
the incoming edges, that is,
a
j
= ReLU(
∑
d
i
=1
(
w
[1]
j
)
i
x
i
)
.
visualized in the dependency graph in Figure 7.3 because all the intermediate
variables
a
i
’s depend on all the inputs
x
i
’s.
For full generality, a two-layer fully-connected neural network with
m
hidden units and
d
dimensional input
x
∈
R
d
is defined as
∀
j
∈
[1
, ..., m
]
,
z
j
=
w
[1]
j
>
x
+
b
[1]
j
where
w
[1]
j
∈
R
d
, b
[1]
j
∈
R
(7.10)
a
j
= ReLU(
z
j
)
,
a
= [
a
1
, . . . , a
m
]
>
∈
R
m
h
θ
(
x
) =
w
[2]
>
a
+
b
[2]
where
w
[2]
∈
R
m
, b
[2]
∈
R
,
(7.11)
Note that by default the vectors in
R
d
are viewed as column vectors, and
in particular
a
is a column vector with components
a
1
, a
2
, ..., a
m
. The indices
[1]
and
[2]
are used to distinguish two sets of parameters: the
w
[1]
j
’s (each of
which is a vector in
R
d
) and
w
[2]
(which is a vector in
R
m
). We will have
more of these later.
Vectorization.
Before we introduce neural networks with more layers and
more complex structures, we will simplify the expressions for neural networks
with more matrix and vector notations.
Another important motivation of
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
87
vectorization is the speed perspective in the implementation.
In order to
implement a neural network efficiently, one must be careful when using for
loops. The most natural way to implement equation (7.10) in code is perhaps
to use a for loop. In practice, the dimensionalities of the inputs and hidden
units are high. As a result, code will run very slowly if you use for loops.
Leveraging the parallelism in GPUs is/was crucial for the progress of deep
learning.
This gave rise to
vectorization
. Instead of using for loops, vectorization
takes advantage of matrix algebra and highly optimized numerical linear
algebra packages (e.g., BLAS) to make neural network computations run
quickly.
Before the deep learning era, a for loop may have been sufficient
on smaller datasets, but modern deep networks and state-of-the-art datasets
will be infeasible to run with for loops.
We vectorize the two-layer fully-connected neural network as below. We
define a weight matrix
W
[1]
in
R
m
×
d
as the concatenation of all the vectors
w
[1]
j
’s in the following way:
W
[1]
=
—
w
[1]
1
>
—
—
w
[1]
2
>
—
.
.
.
—
w
[1]
m
>
—
∈
R
m
×
d
(7.12)
Now by the definition of matrix vector multiplication, we can write
z
=
[
z
1
, . . . , z
m
]
>
∈
R
m
as
z
1
.
.
.
.
.
.
z
m
|
{z
}
z
∈
R
m
×
1
=
—
w
[1]
1
>
—
—
w
[1]
2
>
—
.
.
.
—
w
[1]
m
>
—
|
{z
}
W
[1]
∈
R
m
×
d
x
1
x
2
.
.
.
x
d
|
{z
}
x
∈
R
d
×
1
+
b
[1]
1
b
[1]
2
.
.
.
b
[1]
m
|
{z
}
b
[1]
∈
R
m
×
1
(7.13)
Or succinctly,
z
=
W
[1]
x
+
b
[1]
(7.14)
We remark again that a vector in
R
d
in this notes, following the conventions
previously established, is automatically viewed as a column vector, and can
also be viewed as a
d
×
1 dimensional matrix.
(Note that this is different
from numpy where a vector is viewed as a row vector in broadcasting.)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
88
Computing the activations
a
∈
R
m
from
z
∈
R
m
involves an element-
wise non-linear application of the ReLU function, which can be computed in
parallel efficiently. Overloading ReLU for element-wise application of ReLU
(meaning, for a vector
t
∈
R
d
, ReLU(
t
) is a vector such that ReLU(
t
)
i
=
ReLU(
t
i
)), we have
a
= ReLU(
z
)
(7.15)
Define
W
[2]
= [
w
[2]
>
]
∈
R
1
×
m
similarly.
Then, the model in equa-
tion (7.11) can be summarized as
a
= ReLU(
W
[1]
x
+
b
[1]
)
h
θ
(
x
) =
W
[2]
a
+
b
[2]
(7.16)
Here
θ
consists of
W
[1]
, W
[2]
(often referred to as the weight matrices) and
b
[1]
, b
[2]
(referred to as the biases). The collection of
W
[1]
, b
[1]
is referred to as
the first layer, and
W
[2]
, b
[2]
the second layer. The activation
a
is referred to as
the hidden layer. A two-layer neural network is also called one-hidden-layer
neural network.
Multi-layer fully-connected neural networks.
With this succinct no-
tations, we can stack more layers to get a deeper fully-connected neu-
ral network.
Let
r
be the number of layers (weight matrices).
Let
W
[1]
, . . . , W
[
r
]
, b
[1]
, . . . , b
[
r
]
be the weight matrices and biases of all the layers.
Then a multi-layer neural network can be written as
a
[1]
= ReLU(
W
[1]
x
+
b
[1]
)
a
[2]
= ReLU(
W
[2]
a
[1]
+
b
[2]
)
· · ·
a
[
r
-
1]
= ReLU(
W
[
r
-
1]
a
[
r
-
2]
+
b
[
r
-
1]
)
h
θ
(
x
) =
W
[
r
]
a
[
r
-
1]
+
b
[
r
]
(7.17)
We note that the weight matrices and biases need to have compatible
dimensions for the equations above to make sense. If
a
[
k
]
has dimension
m
k
,
then the weight matrix
W
[
k
]
should be of dimension
m
k
×
m
k
-
1
, and the bias
b
[
k
]
∈
R
m
k
. Moreover,
W
[1]
∈
R
m
1
×
d
and
W
[
r
]
∈
R
1
×
m
r
-
1
.
The total number of neurons in the network is
m
1
+
· · ·
+
m
r
, and the
total number of parameters in this network is (
d
+1)
m
1
+(
m
1
+1)
m
2
+
· · ·
+
(
m
r
-
1
+ 1)
m
r
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
89
Sometimes for notational consistency we also write
a
[0]
=
x
, and
a
[
r
]
=
h
θ
(
x
). Then we have simple recursion that
a
[
k
]
= ReLU(
W
[
k
]
a
[
k
-
1]
+
b
[
k
]
)
,
∀
k
= 1
, . . . , r
-
1
(7.18)
Note that this would have be true for
k
=
r
if there were an additional
ReLU in equation (7.17), but often people like to make the last layer linear
(aka without a ReLU) so that negative outputs are possible and it’s easier
to interpret the last layer as a linear model. (More on the interpretability at
the “connection to kernel method” paragraph of this section.)
Other activation functions.
The activation function ReLU can be re-
placed by many other non-linear function
σ
(
·
) that maps
R
to
R
such as
σ
(
z
) =
1
1 +
e
-
z
(sigmoid)
(7.19)
σ
(
z
) =
e
z
-
e
-
z
e
z
+
e
-
z
(tanh)
(7.20)
Why do we not use the identity function for
σ
(
z
)
?
That is, why
not use
σ
(
z
) =
z
? Assume for sake of argument that
b
[1]
and
b
[2]
are zeros.
Suppose
σ
(
z
) =
z
, then for two-layer neural network, we have that
h
θ
(
x
) =
W
[2]
a
[1]
(7.21)
=
W
[2]
σ
(
z
[1]
)
by definition
(7.22)
=
W
[2]
z
[1]
since
σ
(
z
) =
z
(7.23)
=
W
[2]
W
[1]
x
from Equation (7.13)
(7.24)
=
˜
Wx
where
˜
W
=
W
[2]
W
[1]
(7.25)
Notice how
W
[2]
W
[1]
collapsed into
˜
W
.
This is because applying a linear function to another linear function will
result in a linear function over the original input (i.e., you can construct a
˜
W
such that
˜
Wx
=
W
[2]
W
[1]
x
). This loses much of the representational power
of the neural network as often times the output we are trying to predict
has a non-linear relationship with the inputs. Without non-linear activation
functions, the neural network will simply perform linear regression.
Connection to the Kernel Method.
In the previous lectures, we covered
the concept of feature maps.
Recall that the main motivation for feature
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
90
maps is to represent functions that are non-linear in the input
x
by
θ
>
φ
(
x
),
where
θ
are the parameters and
φ
(
x
), the feature map, is a handcrafted
function non-linear in the raw input
x
.
The performance of the learning
algorithms can significantly depends on the choice of the feature map
φ
(
x
).
Oftentimes people use domain knowledge to design the feature map
φ
(
x
) that
suits the particular applications. The process of choosing the feature maps
is often referred to as
feature engineering
.
We can view deep learning as a way to automatically learn the right
feature map (sometimes also referred to as “the representation”) as follows.
Suppose we denote by
β
the collection of the parameters in a fully-connected
neural networks (equation (7.17)) except those in the last layer.
Then we
can abstract right
a
[
r
-
1]
as a function of the input
x
and the parameters in
β
:
a
[
r
-
1]
=
φ
β
(
x
). Now we can write the model as
h
θ
(
x
) =
W
[
r
]
φ
β
(
x
) +
b
[
r
]
(7.26)
When
β
is fixed, then
φ
β
(
·
) can viewed as a feature map, and therefore
h
θ
(
x
)
is just a linear model over the features
φ
β
(
x
).
However, we will train the
neural networks, both the parameters in
β
and the parameters
W
[
r
]
, b
[
r
]
are
optimized, and therefore we are not learning a linear model in the feature
space, but also learning a good feature map
φ
β
(
·
) itself so that it’s possi-
ble to predict accurately with a linear model on top of the feature map.
Therefore, deep learning tends to depend less on the domain knowledge of
the particular applications and requires often less feature engineering. The
penultimate layer
a
[
r
]
is often (informally) referred to as the learned features
or representations in the context of deep learning.
In the example of house price prediction, a fully-connected neural network
does not need us to specify the intermediate quantity such “family size”, and
may automatically discover some useful features in the last penultimate layer
(the activation
a
[
r
-
1]
), and use them to linearly predict the housing price.
Often the feature map / representation obtained from one datasets (that is,
the function
φ
β
(
·
) can be also useful for other datasets, which indicates they
contain essential information about the data. However, oftentimes, the neural
network will discover complex features which are very useful for predicting
the output but may be difficult for a human to understand or interpret. This
is why some people refer to neural networks as a
black box
, as it can be
difficult to understand the features it has discovered.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
91
7.3
Backpropagation
In this section, we introduce backpropgation or auto-differentiation, which
computes the gradient of the loss
∇
J
(
j
)
(
θ
) efficiently. We will start with an
informal theorem that states that as long as a real-valued function
f
can be
efficiently computed/evaluated by a differentiable network or circuit, then its
gradient can be efficiently computed in a similar time. We will then show
how to do this concretely for fully-connected neural networks.
Because the formality of the general theorem is not the main focus here,
we will introduce the terms with informal definitions.
By a differentiable
circuit or a differentiable network, we mean a composition of a sequence of
differentiable arithmetic operations (additions, subtraction, multiplication,
divisions, etc) and elementary differentiable functions (ReLU, exp, log, sin,
cos, etc.). Let the size of the circuit be the total number of such operations
and elementary functions. We assume that each of the operations and func-
tions, and their derivatives or partial derivatives ecan be computed in
O
(1)
time in the computer.
Theorem 7.3.1:
[backpropagation or auto-differentiation, informally stated]
Suppose a differentiable circuit of size
N
computes a real-valued function
f
:
R
‘
→
R
. Then, the gradient
∇
f
can be computed in time
O
(
N
)
, by a
circuit of size
O
(
N
)
.
4
We note that the loss function
J
(
j
)
(
θ
) for
j
-th example can be indeed
computed by a sequence of operations and functions involving additions,
subtraction, multiplications, and non-linear activations. Thus the theorem
suggests that we should be able to compute the
∇
J
(
j
)
(
θ
) in a similar time
to that for computing
J
(
j
)
(
θ
) itself. This does not only apply to the fully-
connected neural network introduced in the Section 7.2, but also many other
types of neural networks.
In the rest of the section, we will showcase how to compute the gradient of
the loss efficiently for fully-connected neural networks using backpropagation.
Even though auto-differentiation or backpropagation is implemented in all
the deep learning packages such as tensorflow and pytorch, understanding it
is very helpful for gaining insights into the working of deep learning.
4
We note if the output of the function
f
does not depend on some of the input co-
ordinates, then we set by default the gradient w.r.t that coordinate to zero.
Setting to
zero does not count towards the total runtime here in our accounting scheme. This is why
when
N
≤
‘
, we can compute the gradient in
O
(
N
) time, which might be potentially even
less than
‘
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
92
7.3.1
Preliminary: chain rule
We first recall the chain rule in calculus. Suppose the variable
J
depends on
the variables
θ
1
, . . . , θ
p
via the intermediate variable
g
1
, . . . , g
k
:
g
j
=
g
j
(
θ
1
, . . . , θ
p
)
,
∀
j
∈ {
1
,
· · ·
, k
}
(7.27)
J
=
J
(
g
1
, . . . , g
k
)
(7.28)
Here we overload the meaning of
g
j
’s: they denote both the intermediate
variables but also the functions used to compute the intermediate variables.
Then, by the chain rule, we have that
∀
i
,
∂J
∂θ
i
=
k
X
j
=1
∂J
∂g
j
∂g
j
∂θ
i
(7.29)
For the ease of invoking the chain rule in the following subsections in various
ways, we will call
J
the output variable,
g
1
, . . . , g
k
intermediate variables,
and
θ
1
, . . . , θ
p
the input variable in the chain rule.
7.3.2
One-neuron neural networks
Simplifying notations:
In the rest of the section, we will consider a
generic input
x
and compute the gradient of
h
θ
(
x
) w.r.t
θ
. For simplicity,
we use
o
as a shorthand for
h
θ
(
x
) (
o
stands for
output
). For simplicity, with
slight abuse of notation, we use
J
=
1
2
(
y
-
o
)
2
to denote the loss function.
(Note that this overrides the definition of
J
as the total loss in Section 7.1.)
Our goal is to compute the derivative of
J
w.r.t the parameter
θ
.
We first consider the neural network with one neuron defined in equa-
tion (7.7).
Recall that we compute the loss function via the following se-
quential steps:
z
=
w
>
x
+
b
(7.30)
o
= ReLU(
z
)
(7.31)
J
=
1
2
(
y
-
o
)
2
(7.32)
By the chain rule with
J
as the output variable,
o
as the intermediate variable,
and
w
i
the input variable, we have that
∂J
∂w
i
=
∂J
∂o
·
∂o
∂w
i
(7.33)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
93
Invoking the chain rule with
o
as the output variable,
z
as the intermediate
variable, and
w
i
the input variable, we have that
∂o
∂w
i
=
∂o
∂z
·
∂z
∂w
i
Combining the equation above with equation (7.33), we have
∂J
∂w
i
=
∂J
∂o
·
∂o
∂z
·
∂z
∂w
i
= (
o
-
y
)
·
ReLU
0
(
z
)
·
x
i
(because
∂J
∂o
= (
o
-
y
) and
∂o
∂z
= ReLU
0
(
z
) and
∂z
∂w
i
=
x
i
)
Here, the key is that we reduce the computation of
∂J
∂w
i
to the computa-
tion of three simpler more “local” objects
∂J
∂o
,
∂o
∂z
, and
∂z
∂w
i
, which are much
simpler to compute because
J
directly depends on
o
via equation (7.32),
o
directly depends on
a
via equation (7.31), and
z
directly depends on
w
i
via
equation (7.30). Note that in a vectorized form, we can also write
∇
w
J
= (
o
-
y
)
·
ReLU
0
(
z
)
·
x
Similarly, we compute the gradient w.r.t
b
by
∂J
∂b
=
∂J
∂o
·
∂o
∂z
·
∂z
∂b
= (
o
-
y
)
·
ReLU
0
(
z
)
(because
∂J
∂o
= (
o
-
y
) and
∂o
∂z
= ReLU
0
(
z
) and
∂z
∂b
= 1)
7.3.3
Two-layer neural networks: a low-level unpacked
computation
Note:
this subsection derives the derivatives with low-level notations to
help you build up intuition on backpropagation.
If you are looking for a
clean formula, or you are familiar with matrix derivatives, then feel free to
jump to the next subsection directly.
Now we consider the two-layer neural network defined in equation (7.11).
We compute the loss
J
by following sequence of operations
∀
j
∈
[1
, ..., m
]
,
z
j
=
w
[1]
j
>
x
+
b
[1]
j
where
w
[1]
j
∈
R
d
, b
[1]
j
a
j
= ReLU(
z
j
)
,
a
= [
a
1
, . . . , a
m
]
>
∈
R
m
o
=
w
[2]
>
a
+
b
[2]
where
w
[2]
∈
R
m
, b
[2]
∈
R
J
=
1
2
(
y
-
o
)
2
(7.34)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
94
We will use (
w
[2]
)
‘
to denote the
‘
-th coordinate of
w
[2]
, and (
w
[1]
j
)
‘
to denote
the
‘
-coordinate of
w
[1]
j
. (We will avoid using these cumbersome notations
once we figure out how to write everything in matrix and vector forms.)
By invoking chain rule with
J
as the output variable,
o
as intermediate
variable, and (
w
[2]
)
‘
as the input variable, we have
∂J
∂
(
w
[2]
)
‘
=
∂J
∂o
∂o
∂
(
w
[2]
)
‘
= (
o
-
y
)
∂o
∂
(
w
[2]
)
‘
= (
o
-
y
)
a
‘
It’s more challenging to compute
∂J
∂
(
w
[1]
j
)
‘
.
Towards computing it, we first
invoke the chain rule with
J
as the output variable,
z
j
as the intermediate
variable, and (
w
[1]
j
)
‘
as the input variable.
∂J
∂
(
w
[1]
j
)
‘
=
∂J
∂z
j
·
∂z
j
∂
(
w
[1]
j
)
‘
=
∂J
∂z
j
·
x
‘
(becaues
∂z
j
∂
(
w
[1]
j
)
‘
=
x
‘
.)
Thus, it suffices to compute the
∂J
∂z
j
. We invoke the chain rule with
J
as the
output variable,
a
j
as the intermediate variable, and
z
j
as the input variable,
∂J
∂z
j
=
∂J
∂a
j
∂a
j
∂z
j
=
∂J
∂a
j
ReLU
0
(
z
j
)
Now it suffices to compute
∂J
∂a
j
, and we invoke the chain rule with
J
as the
output variable,
o
as the intermediate variable, and
a
j
as the input variable,
∂J
∂a
j
=
∂J
∂o
∂o
∂a
j
= (
o
-
y
)
·
(
w
[2]
)
j
Now combining the equations above, we obtain
∂J
∂
(
w
[1]
j
)
‘
= (
o
-
y
)
·
(
w
[2]
)
j
ReLU
0
(
z
j
)
x
‘
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
95
Next we gauge the runtime of computing these partial derivatives.
Let
p
denotes the total number of parameters in the network. We note that
p
≥
md
where
m
is the number of hidden units and
d
is the input dimension. For
every
j
and
‘
, to compute
∂J
∂
(
w
[1]
j
)
‘
, apparently we need to compute at least
the output
o
, which takes at least
p
≥
md
operations. Therefore at the first
glance computing a single gradient takes at least
md
time, and the total time
to compute the derivatives w.r.t to all the parameters is at least (
md
)
2
, which
is inefficient.
However, the key of the backpropagation is that for different choices of
‘
,
the formulas above for computing
∂J
∂
(
w
[1]
j
)
‘
share many terms, such as, (
o
-
y
),
(
w
[2]
)
j
and ReLU
0
(
z
j
). This suggests that we can re-organize the computation
to leverage the shared computation.
It turns out the crucial shared quantities in these formulas are
∂J
∂o
,
∂J
∂z
1
, . . . ,
∂J
∂z
m
.
We now write the following formulas to compute the gradi-
ents efficiently in Algorithm 3.
Algorithm 3
Backpropagation for two-layer neural networks
1:
Compute the values of
z
1
, . . . , z
m
,
a
1
, . . . , a
m
and
o
as in the definition of
neural network (equation (7.34)).
2:
Compute
∂J
∂o
= (
o
-
y
).
3:
Compute
∂J
∂z
j
for
j
= 1
, . . . , m
by
∂J
∂z
j
=
∂J
∂o
∂o
∂a
j
∂a
j
∂z
j
=
∂J
∂o
·
(
w
[2]
)
j
·
ReLU
0
(
z
j
)
(7.35)
4:
Compute
∂J
∂
(
w
[1]
j
)
‘
,
∂J
∂b
[1]
j
,
∂J
∂
(
w
[2]
)
j
, and
∂J
∂b
[2]
by
∂J
∂
(
w
[1]
j
)
‘
=
∂J
∂z
j
·
∂z
j
∂
(
w
[1]
j
)
‘
=
∂J
∂z
j
·
x
‘
∂J
∂b
[1]
j
=
∂J
∂z
j
·
∂z
j
∂b
[1]
j
=
∂J
∂z
j
∂J
∂
(
w
[2]
)
j
=
∂J
∂o
∂o
∂
(
w
[2]
)
j
=
∂J
∂o
·
a
j
∂J
∂b
[2]
=
∂J
∂o
∂o
∂b
[2]
=
∂J
∂o
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
96
7.3.4
Two-layer neural network with vector notation
As we have done before in the definition of neural networks, the equations for
backpropagation becomes much cleaner with proper matrix notation. Here
we state the algorithm first and also provide a cleaner proof via matrix cal-
culus.
Let
δ
[2]
,
∂J
∂o
∈
R
δ
[1]
,
∂J
∂z
∈
R
m
(7.36)
Here we note that when
A
is a real-valued variable,
5
and
B
is a vector or
matrix variable, then
∂A
∂B
denotes the collection of the partial derivatives with
the same shape as
B
.
6
In other words, if
B
is a matrix of dimension
m
×
d
,
then
∂A
∂B
is a matrix in
R
m
×
d
with
∂A
∂B
ij
as the
ij
th-entry. Let
v
w
denote
the entry-wise product of two vectors
v
and
w
of the same dimension. Now
we are ready to describe backpropagation in Algorithm 4.
Algorithm 4
Back-propagation for two-layer neural networks in vectorized
notations.
.
1:
Compute the values of
z
∈
R
m
,
a
∈
R
m
, and
o
2:
Compute
δ
[2]
= (
o
-
y
)
∈
R
3:
Compute
δ
[1]
= (
o
-
y
)
·
W
[2]
>
ReLU
0
(
z
)
∈
R
m
×
1
4:
Compute
∂J
∂W
[2]
=
δ
[2]
a
>
∈
R
1
×
m
∂J
∂b
[2]
=
δ
[2]
∈
R
∂J
∂W
[1]
=
δ
[1]
x
>
∈
R
m
×
d
∂J
∂b
[1]
=
δ
[1]
∈
R
m
5
We will avoid using the notation
∂A
∂B
for
A
that is not a real-valued variable.
6
If you are familiar with the notion of total derivatives, we note that the dimensionality
here is different from that for total derivatives.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
97
Derivation using the chain rule for matrix multiplication.
To
have a succinct derivation of the backpropagation algorithm in Algorithm 4
without working with the complex indices, we state the extensions of the
chain rule in vectorized notations.
It requires more knowledge of matrix
calculus to state the most general result, and therefore we will introduce
a few special cases that are most relevant for deep learning.
Suppose
J
is a real-valued output variable,
z
∈
R
m
is the intermediate variable and
W
∈
R
m
×
d
, u
∈
R
d
are the input variables. Suppose they satisfy:
z
=
Wu
+
b,
where
W
∈
R
m
×
d
J
=
J
(
z
)
(7.37)
Then we can compute
∂J
∂u
and
∂J
∂W
by:
∂J
∂u
=
W
>
∂J
∂z
(7.38)
∂J
∂W
=
∂J
∂z
·
u
>
(7.39)
∂J
∂b
=
∂J
∂z
(7.40)
We can verify the dimensionality is indeed compatible because
∂J
∂z
∈
R
m
,
W
>
∈
R
d
×
m
,
∂J
∂u
∈
R
d
,
∂J
∂W
∈
R
m
×
d
,
u
>
∈
R
1
×
d
.
Here the chain rule in equation (7.38) only works for the special cases
where
z
=
Wu
. Another useful case is the following:
a
=
σ
(
z
)
,
where
σ
is an element-wise activation,
z, a
∈
R
d
J
=
J
(
a
)
Then, we have that
∂J
∂z
=
∂J
∂a
σ
0
(
z
)
(7.41)
where
σ
0
(
·
) is the element-wise derivative of the activation function
σ
, and
is element-wise product of two vectors of the same dimensionality.
Using equation (7.38), (7.39),and (7.41), we can verify the correctness of
Algorithm 4. Indeed, using the notations in the two-layer neural network
∂J
∂z
=
∂J
∂a
ReLU
0
(
z
)
(
by invoking equation (7.41) with setting
J
←
J
,
a
←
a
,
z
←
a
,
σ
←
ReLU.
)
= (
o
-
y
)
W
[2]
>
ReLU
0
(
z
)
(
by invoking equation (7.38) with setting
J
←
J
,
z
←
o
,
W
←
W
[2]
,
u
←
a
,
b
←
b
[2]
)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
98
Therefore,
δ
[1]
=
∂J
∂z
, and we verify the correctness of Line 3 in Algorithm 4.
Similarly, let’s verify the third equation in Line 4,
∂J
∂W
[1]
=
∂J
∂z
·
x
>
(
by invoking equation (7.39) with setting
J
←
J
,
z
←
z
,
W
←
W
[1]
,
u
←
x
,
b
←
b
[1]
)
=
δ
[1]
x
>
(because we have proved
δ
[1]
=
∂J
∂z
)
7.3.5
Multi-layer neural networks
In this section, we will derive the backpropagation algorithms for the model
defined in (7.17). Recall that we have
a
[1]
= ReLU(
W
[1]
x
+
b
[1]
)
a
[2]
= ReLU(
W
[2]
a
[1]
+
b
[2]
)
· · ·
a
[
r
-
1]
= ReLU(
W
[
r
-
1]
a
[
r
-
2]
+
b
[
r
-
1]
)
a
[
r
]
=
z
[
r
]
=
W
[
r
]
a
[
r
-
1]
+
b
[
r
]
J
=
1
2
(
a
[
r
]
-
y
)
2
Here we define both
a
[
r
]
and
z
[
r
]
as
h
θ
(
x
) for notational simplicity.
Define
δ
[
k
]
=
∂J
∂z
[
k
]
(7.42)
The backpropagation algorithm computes
δ
[
k
]
’s from
k
=
r
to 1, and
computes
∂J
∂W
[
k
]
from
δ
[
k
]
as described in Algorithm 5.
7.4
Vectorization over training examples
As we discussed in Section 7.1, in the implementation of neural networks,
we will leverage the parallelism across the multiple examples.
This means
that we will need to write the forward pass (the evaluation of the outputs)
of the neural network and the backward pass (backpropagation) for multiple
training examples in matrix notation.
The basic idea.
The basic idea is simple. Suppose you have a training
set with three examples
x
(1)
, x
(2)
, x
(3)
.
The first-layer activations for each
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
99
Algorithm 5
Back-propagation for multi-layer neural networks.
.
1:
Compute and store the values of
a
[
k
]
’s and
z
[
k
]
’s for
k
= 1
, . . . , r
-
1, and
J
.
.
This is often called the “forward pass”
2:
Compute
δ
[
r
]
=
∂J
∂z
[
r
]
= (
z
[
r
]
-
o
).
3:
for
k
=
r
-
1 to 1
do
4:
Compute
δ
[
k
]
=
∂J
∂z
[
k
]
=
W
[
k
+1]
>
δ
[
k
+1]
ReLU
0
(
z
[
k
]
)
5:
Compute
∂J
∂W
[
k
+1]
=
δ
[
k
+1]
a
[
k
]
>
∂J
∂b
[
k
+1]
=
δ
[
k
+1]
example are as follows:
z
[1](1)
=
W
[1]
x
(1)
+
b
[1]
z
[1](2)
=
W
[1]
x
(2)
+
b
[1]
z
[1](3)
=
W
[1]
x
(3)
+
b
[1]
Note the difference between square brackets [
·
], which refer to the layer num-
ber, and parenthesis (
·
), which refer to the training example number.
In-
tuitively, one would implement this using a for loop. It turns out, we can
vectorize these operations as well. First, define:
X
=
|
|
|
x
(1)
x
(2)
x
(3)
|
|
|
∈
R
d
×
3
(7.43)
Note that we are stacking training examples in columns and
not
rows. We
can then combine this into a single unified formulation:
Z
[1]
=
|
|
|
z
[1](1)
z
[1](2)
z
[1](3)
|
|
|
=
W
[1]
X
+
b
[1]
(7.44)
You may notice that we are attempting to add
b
[1]
∈
R
4
×
1
to
W
[1]
X
∈
R
4
×
3
.
Strictly following the rules of linear algebra, this is not allowed.
In
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
100
practice however, this addition is performed using
broadcasting
. We create
an intermediate
˜
b
[1]
∈
R
4
×
3
:
˜
b
[1]
=
|
|
|
b
[1]
b
[1]
b
[1]
|
|
|
(7.45)
We can then perform the computation:
Z
[1]
=
W
[1]
X
+
˜
b
[1]
. Often times, it
is not necessary to explicitly construct
˜
b
[1]
. By inspecting the dimensions in
(7.44), you can assume
b
[1]
∈
R
4
×
1
is correctly broadcast to
W
[1]
X
∈
R
4
×
3
.
The matricization approach as above can easily generalize to multiple
layers, with one subtlety though, as discussed below.
Complications/Subtlety in the Implementation.
All the deep learn-
ing packages or implementations put the data points in the rows of a data
matrix. (If the data point itself is a matrix or tensor, then the data are con-
centrated along the zero-th dimension.) However, most of the deep learning
papers use a similar notation to these notes where the data points are treated
as column vectors.
7
There is a simple conversion to deal with the mismatch:
in the implementation, all the columns become row vectors, row vectors be-
come column vectors, all the matrices are transposed, and the orders of the
matrix multiplications are flipped. In the example above, using the row ma-
jor convention, the data matrix is
X
∈
R
3
×
d
, the first layer weight matrix
has dimensionality
d
×
m
(instead of
m
×
d
as in the two layer neural net
section), and the bias vector
b
[1]
∈
R
1
×
m
. The computation for the hidden
activation becomes
Z
[1]
=
XW
[1]
+
b
[1]
∈
R
3
×
m
(7.46)
7
The instructor suspects that this is mostly because in mathematics we naturally mul-
tiply a matrix to a vector on the left hand side.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Part III
Generalization and
regularization
101
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 8
Generalization
This chapter discusses tools to analyze and understand the generaliza-
tion of machine learning models, i.e, their performances on unseen test
examples.
Recall that for supervised learning problems, given a train-
ing dataset
{
(
x
(
i
)
, y
(
i
)
)
}
n
i
=1
, we typically learn a model
h
θ
by minimizing a
loss/cost function
J
(
θ
), which encourages
h
θ
to fit the data.
E.g., when
the loss function is the least square loss (aka mean squared error), we have
J
(
θ
) =
1
n
∑
n
i
=1
(
y
(
i
)
-
h
θ
(
x
(
i
)
))
2
. This loss function for training purposes is
oftentimes referred to as the
training
loss/error/cost.
However, minimizing the training loss is
not
our ultimate goal—it is
merely our approach towards the goal of learning a predictive model. The
most important evaluation metric of a model is the loss on unseen test exam-
ples, which is oftentimes referred to as the test error. Formally, we sample a
test example (
x, y
) from the so-called test distribution
D
, and measure the
model’s error on it, by, e.g., the mean squared error, (
h
θ
(
x
)
-
y
)
2
. The ex-
pected loss/error over the randomness of the test example is called the test
loss/error,
1
L
(
θ
) =
E
(
x,y
)
∼D
[(
y
-
h
θ
(
x
))
2
]
(8.1)
Note that the measurement of the error involves computing the expectation,
and in practice, it can be approximated by the average error on many sampled
test examples, which are referred to as the test dataset. Note that the key
difference here between training and test datasets is that the test examples
1
In theoretical and statistical literature, we oftentimes call the uniform distribution
over the training set
{
(
x
(
i
)
, y
(
i
)
)
}
n
i
=1
, denoted by
b
D
, an empirical distribution, and call
D
the population distribution.
Partly because of this, the training loss is also referred
to as the empirical loss/risk/error, and the test loss is also referred to as the population
loss/risk/error.
102
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
103
are
unseen
, in the sense that the training procedure has not used the test
examples. In classical statistical learning settings, the training examples are
also drawn from the same distribution as the test distribution
D
, but still
the test examples are unseen by the learning procedure whereas the training
examples are seen.
2
Because of this key difference between training and test datasets, even
if they are both drawn from the same distribution
D
, the test error is not
necessarily always close to the training error.
3
As a result, successfully min-
imizing the training error may not always lead to a small test error.
We
typically say the model
overfits
the data if the model predicts accurately on
the training dataset but doesn’t generalize well to other test examples, that
is, if the training error is small but the test error is large. We say the model
underfits
the data if the training error is relatively large
4
(and in this case,
typically the test error is also relatively large.)
This chapter studies how the test error is influenced by the learning pro-
cedure, especially the choice of model parameterizations. We will decompose
the test error into “bias” and “variance” terms and study how each of them is
affected by the choice of model parameterizations and their tradeoffs. Using
the bias-variance tradeoff, we will discuss when overfitting and underfitting
will occur and be avoided.
We will also discuss the double descent phe-
nomenon in Section 8.2 and some classical theoretical results in Section 8.3.
2
These days, researchers have increasingly been more interested in the setting with
“domain shift”, that is, the training distribution and test distribution are different.
3
the difference between test error and training error is often referred to as the gener-
alization gap. The term
generalization error
in some literature means the test error, and
in some other literature means the generalization gap.
4
e.g., larger than the intrinsic noise level of the data in regression problems.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
104
8.1
Bias-variance tradeoff
Figure 8.1: A running example of training and test dataset for this section.
As an illustrating example, we consider the following training dataset and
test dataset, which are also shown in Figure 8.1. The training inputs
x
(
i
)
’s are
randomly chosen and the outputs
y
(
i
)
are generated by
y
(
i
)
=
h
?
(
x
(
i
)
) +
ξ
(
i
)
where the function
h
?
(
·
) is a quadratic function and is shown in Figure 8.1
as the solid line, and
ξ
(
i
)
is the a observation noise assumed to be generated
from
∼
N
(0
, σ
2
).
A test example (
x, y
) also has the same input-output
relationship
y
=
h
?
(
x
) +
ξ
where
ξ
∼
N
(0
, σ
2
). It’s impossible to predict the
noise
ξ
, and therefore essentially our goal is to recover the function
h
?
(
·
).
We will consider the test error of learning various types of models. When
talking about linear regression, we discussed the problem of whether to fit
a “simple” model such as the linear “
y
=
θ
0
+
θ
1
x
,” or a more “complex”
model such as the polynomial “
y
=
θ
0
+
θ
1
x
+
· · ·
θ
5
x
5
.”
We start with fitting a linear model, as shown in Figure 8.2. The best
fitted linear model cannot predict
y
from
x
accurately even on the training
dataset, let alone on the test dataset. This is because the true relationship
between
y
and
x
is not linear—any linear model is far away from the true
function
h
?
(
·
). As a result, the training error is large and this is a typical
situation of
underfitting
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
105
Figure 8.2: The best fit linear model has large training and test errors.
The issue cannot be mitigated with more training examples—even with
a very large amount of, or even infinite training examples, the best fitted
linear model is still inaccurate and fails to capture the structure of the data
(Figure 8.3). Even if the noise is not present in the training data, the issue
still occurs (Figure 8.4). Therefore, the fundamental bottleneck here is the
linear model family’s inability to capture the structure in the data—linear
models cannot represent the true quadratic function
h
?
—, but not the lack of
the data. Informally, we define the
bias
of a model to be the test error even
if we were to fit it to a very (say, infinitely) large training dataset. Thus, in
this case, the linear model suffers from large bias, and underfits (i.e., fails to
capture structure exhibited by) the data.
Figure 8.3:
The best fit linear
model on a much larger dataset
still has a large training error.
Figure 8.4:
The best fit linear
model on a noiseless dataset also
has a large training/test error.
Next, we fit a 5th-degree polynomial to the data. Figure 8.5 shows that
it fails to learn a good model either. However, the failure pattern is different
from the linear model case. Specifically, even though the learnt 5th-degree
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
106
polynomial did a very good job predicting
y
(
i
)
’s from
x
(
i
)
’s for training ex-
amples, it does not work well on test examples (Figure 8.5). In other words,
the model learnt from the training set does not
generalize
well to other test
examples—the test error is high. Contrary to the behavior of linear models,
the bias of the 5-th degree polynomials is small—if we were to fit a 5-th de-
gree polynomial to an extremely large dataset, the resulting model would be
close to a quadratic function and be accurate (Figure 8.6). This is because
the family of 5-th degree polynomials contains all the quadratic functions
(setting
θ
5
=
θ
4
=
θ
3
= 0 results in a quadratic function), and, therefore,
5-th degree polynomials are in principle capable of capturing the structure
of the data.
Figure 8.5: Best fit 5-th degree polynomial has zero training error, but still
has a large test error and does not recover the the ground truth. This is a
classic situation of overfitting.
Figure 8.6: The best fit 5-th degree polynomial on a huge dataset nearly
recovers the ground-truth—suggesting that the culprit in Figure 8.5 is the
variance (or lack of data) but not bias.
The failure of fitting 5-th degree polynomials can be captured by another
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
107
component of the test error, called
variance
of a model fitting procedure.
Specifically, when fitting a 5-th degree polynomial as in Figure 8.7, there is a
large risk that we’re fitting patterns in the data that happened to be present
in our
small, finite
training set, but that do not reflect the wider pattern of
the relationship between
x
and
y
. These “spurious” patterns in the training
set are (mostly) due to the observation noise
ξ
(
i
)
, and fitting these spurious
patters results in a model with large test error. In this case, we say the model
has a large variance.
Figure 8.7: The best fit 5-th degree models on three different datasets gen-
erated from the same distribution behave quite differently, suggesting the
existence of a large variance.
The variance can be intuitively (and mathematically, as shown in Sec-
tion 8.1.1) characterized by the amount of variations across models learnt
on multiple different training datasets (drawn from the same underlying dis-
tribution).
The “spurious patterns” are specific to the randomness of the
noise (and inputs) in a particular dataset, and thus are different across mul-
tiple training datasets. Therefore, overfitting to the “spurious patterns” of
multiple datasets should result in very different models.
Indeed, as shown
in Figure 8.7, the models learned on the three different training datasets are
quite different, overfitting to the “spurious patterns” of each datasets.
Often, there is a tradeoff between bias and variance. If our model is too
“simple” and has very few parameters, then it may have large bias (but small
variance), and it typically may suffer from underfittng. If it is too “complex”
and has very many parameters, then it may suffer from large variance (but
have smaller bias), and thus overfitting. See Figure 8.8 for a typical tradeoff
between bias and variance.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
108
Model Complexity
Error
Bias
2
Variance
Test Error (= Bias
2
+Variance)
Optimal Tradeoff
Figure 8.8: An illustration of the typical bias-variance tradeoff.
As we will see formally in Section 8.1.1, the test error can be decomposed
as a summation of bias and variance.
This means that the test error will
have a convex curve as the model complexity increases, and in practice we
should tune the model complexity to achieve the best tradeoff. For instance,
in the example above, fitting a quadratic function does better than either of
the extremes of a first or a 5-th degree polynomial, as shown in Figure 8.9.
Figure 8.9: Best fit quadratic model has small training and test error because
quadratic model achieves a better tradeoff.
Interestingly, the bias-variance tradeoff curves or the test error curves
do not universally follow the shape in Figure 8.8, at least not universally
when the model complexity is simply measured by the number of parameters.
(We will discuss the so-called double descent phenomenon in Section 8.2.)
Nevertheless, the principle of bias-variance tradeoff is perhaps still the first
resort when analyzing and predicting the behavior of test errors.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
109
8.1.1
A mathematical decomposition (for regression)
To formally state the bias-variance tradeoff for regression problems, we con-
sider the following setup (which is an extension of the beginning paragraph
of Section 8.1).
•
Draw a training dataset
S
=
{
x
(
i
)
, y
(
i
)
}
n
i
=1
such that
y
(
i
)
=
h
?
(
x
(
i
)
)+
ξ
(
i
)
where
ξ
(
i
)
∈
N
(0
, σ
2
).
•
Train a model on the dataset
S
, denoted by
ˆ
h
S
.
•
Take a test example (
x, y
) such that
y
=
h
?
(
x
) +
ξ
where
ξ
∼
N
(0
, σ
2
),
and measure the expected test error (averaged over the random draw of
the training set
S
and the randomness of
ξ
)
56
MSE(
x
) =
E
S,ξ
[(
y
-
h
S
(
x
))
2
]
(8.2)
We will decompose the MSE into a bias and variance term. We start by
stating a following simple mathematical tool that will be used twice below.
Claim 8.1.1:
Suppose
A
and
B
are two independent real random variables
and
E
[
A
] = 0. Then,
E
[(
A
+
B
)
2
] =
E
[
A
2
] +
E
[
B
2
].
As a corollary, because a random variable
A
is independent with a con-
stant
c
, when
E
[
A
] = 0, we have
E
[(
A
+
c
)
2
] =
E
[
A
2
] +
c
2
.
The proof of the claim follows from expanding the square:
E
[(
A
+
B
)
2
] =
E
[
A
2
] +
E
[
B
2
] + 2
E
[
AB
] =
E
[
A
2
] +
E
[
B
2
]. Here we used the independence to
show that
E
[
AB
] =
E
[
A
]
E
[
B
] = 0.
Using Claim 8.1.1 with
A
=
ξ
and
B
=
h
?
(
x
)
-
ˆ
h
S
(
x
), we have
MSE(
x
) =
E
[(
y
-
h
S
(
x
))
2
] =
E
[(
ξ
+ (
h
?
(
x
)
-
h
S
(
x
)))
2
]
(8.3)
=
E
[
ξ
2
] +
E
[(
h
?
(
x
)
-
h
S
(
x
))
2
]
(by Claim 8.1.1)
=
σ
2
+
E
[(
h
?
(
x
)
-
h
S
(
x
))
2
]
(8.4)
Then, let’s define
h
avg
(
x
) =
E
S
[
h
S
(
x
)] as the “average model”—the model
obtained by drawing an infinite number of datasets, training on them, and
averaging their predictions on
x
. Note that
h
avg
is a hypothetical model for
analytical purposes that can not be obtained in reality (because we don’t
5
For simplicity, the test input
x
is considered to be fixed here, but the same conceptual
message holds when we average over the choice of
x
’s.
6
The subscript under the expectation symbol is to emphasize the variables that are
considered as random by the expectation operation.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
110
have infinite number of datasets).
It turns out that for many cases,
h
avg
is (approximately) equal to the the model obtained by training on a
single
dataset with infinite samples. Thus, we can also intuitively interpret
h
avg
this
way, which is consistent with our intuitive definition of bias in the previous
subsection.
We can further decompose MSE(
x
) by letting
c
=
h
?
(
x
)
-
h
avg
(
x
) (which is
a constant that does not depend on the choice of
S
!) and
A
=
h
avg
(
x
)
-
h
S
(
x
)
in the corollary part of Claim 8.1.1:
MSE(
x
) =
σ
2
+
E
[(
h
?
(
x
)
-
h
S
(
x
))
2
]
(8.5)
=
σ
2
+ (
h
?
(
x
)
-
h
avg
(
x
))
2
+
E
[(
h
avg
-
h
S
(
x
))
2
]
(8.6)
=
σ
2
|{z}
unavoidable
+ (
h
?
(
x
)
-
h
avg
(
x
))
2
|
{z
}
,
bias
2
+ var(
h
S
(
x
))
|
{z
}
,
variance
(8.7)
We call the second term the bias (square) and the third term the variance. As
discussed before, the bias captures the part of the error that are introduced
due to the lack of expressivity of the model. Recall that
h
avg
can be thought
of as the best possible model learned even with infinite data. Thus, the bias is
not due to the lack of data, but is rather caused by that the family of models
fundamentally cannot approximate the
h
?
. For example, in the illustrating
example in Figure 8.2, because any linear model cannot approximate the
true quadratic function
h
?
, neither can
h
avg
, and thus the bias term has to
be large.
The variance term captures how the random nature of the finite dataset
introduces errors in the learned model.
It measures the sensitivity of the
learned model to the randomness in the dataset. It often decreases as the
size of the dataset increases.
There is nothing we can do about the first term
σ
2
as we can not predict
the noise
ξ
by definition.
Finally, we note that the bias-variance decomposition for classification
is much less clear than for regression problems.
There have been several
proposals, but there is as yet no agreement on what is the “right” and/or
the most useful formalism.
8.2
The double descent phenomenon
Model-wise double descent.
Recent works have demonstrated that the
test error can present a “double descent” phenomenon in a range of machine
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
111
learning models including linear models and deep neural networks.
7
The
conventional wisdom, as discussed in Section 8.1, is that as we increase the
model complexity, the test error first decreases and then increases, as illus-
trated in Figure 8.8. However, in many cases, we empirically observe that
the test error can have a second descent—it first decreases, then increases
to a peak around when the model size is large enough to fit all the training
data very well, and then decreases again in the so-called overparameterized
regime, where the number of parameters is larger than the number of data
points. See Figure 8.10 for an illustration of the typical curves of test errors
against model complexity (measured by the number of parameters). To some
extent, the overparameterized regime with the second descent is considered as
new to the machine learning community—partly because lightly-regularized,
overparameterized models are only extensively used in the deep learning era.
A practical implication of the phenomenon is that one should not hold back
from scaling into and experimenting with over-parametrized models because
the test error may well decrease again to a level even smaller than the previ-
ous lowest point. Actually, in many cases, larger overparameterized models
always lead to a better test performance (meaning there won’t be a second
ascent after the second descent).
# parameters
test error
typically when # parameters
is sufficient to fit the data
classical regime:
bias-variance tradeoff
modern regime:
over-parameterization
Figure 8.10: A typical model-wise double descent phenomenon. As the num-
ber of parameters increases, the test error first decreases when the number of
parameters is smaller than the training data. Then in the overparameterized
regime, the test error decreases again.
7
The discovery of the phenomenon perhaps dates back to Opper [1995, 2001], and has
been recently popularized by Belkin et al. [2020], Hastie et al. [2019], etc.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
112
Sample-wise double descent.
A priori, we would expect that more
training examples always lead to smaller test errors—more samples give
strictly more information for the algorithm to learn from. However, recent
work [Nakkiran, 2019] observes that the test error is not monotonically de-
creasing as we increase the sample size. Instead, as shown in Figure 8.11, the
test error decreases, and then increases and peaks around when the number
of examples (denoted by
n
) is similar to the number of parameters (denoted
by
d
), and then decreases again. We refer to this as the sample-wise dou-
ble descent phenomenon. To some extent, sample-wise double descent and
model-wise double descent are essentially describing similar phenomena—the
test error is peaked when
n
≈
d
.
Explanation and mitigation strategy.
The sample-wise double descent,
or, in particular, the peak of test error at
n
≈
d
, suggests that the existing
training algorithms evaluated in these experiments are far from optimal when
n
≈
d
.
We will be better off by tossing away some examples and run the
algorithms with a smaller sample size to steer clear of the peak.
In other
words, in principle, there are other algorithms that can achieve smaller test
error when
n
≈
d
, but the algorithms evaluated in these experiments fail to
do so. The sub-optimality of the learning procedure appears to be the culprit
of the peak in both sample-wise and model-wise double descent.
Indeed, with an optimally-tuned regularization (which will be discussed
more in Section 9), the test error in the
n
≈
d
regime can be dramatically
improved, and the model-wise and sample-wise double descent are both mit-
igated. See Figure 8.11.
The intuition above only explains the peak in the model-wise and sample-
wise double descent, but does not explain the second descent in the model-
wise double descent—why overparameterized models are able to generalize
so well. The theoretical understanding of overparameterized models is an ac-
tive research area with many recent advances. A typical explanation is that
the commonly-used optimizers such as gradient descent provide an implicit
regularization effect (which will be discussed in more detail in Section 9.2).
In other words, even in the overparameterized regime and with an unregular-
ized loss function, the model is still implicitly regularized, and thus exhibits
a better test performance than an arbitrary solution that fits the data. For
example, for linear models, when
n
d
, the gradient descent optimizer with
zero initialization finds the
minimum norm
solution that fits the data (in-
stead of an arbitrary solution that fits the data), and the minimum norm reg-
ularizer turns out to be a sufficiently good for the overparameterized regime
(but it’s not a good regularizer when
n
≈
d
, resulting in the peak of test
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
113
error).
Figure 8.11:
Left:
The sample-wise double descent phenomenon for linear
models.
Right:
The sample-wise double descent with different regularization
strength for linear models.
Using the optimal regularization parameter
λ
(optimally tuned for each
n
, shown in green solid curve) mitigates double
descent.
Setup:
The data distribution of (
x, y
) is
x
∼ N
(0
, I
d
) and
y
∼
x
>
β
+
N
(0
, σ
2
) where
d
= 500
, σ
= 0
.
5 and
k
β
k
2
= 1.
8
Finally, we also remark that the double descent phenomenon has been
mostly observed when the model complexity is measured by the number of
parameters. It is unclear if and when the number of parameters is the best
complexity measure of a model. For example, in many situations, the norm
of the models is used as a complexity measure.
As shown in Figure 8.12
right, for a particular linear case, if we plot the test error against the norm
of the learnt model, the double descent phenomenon no longer occurs. This
is partly because the norm of the learned model is also peaked around
n
≈
d
(See Figure 8.12 (middle) or Belkin et al. [2019], Mei and Montanari [2022],
and discussions in Section 10.8 of James et al. [2021]).
For deep neural
networks, the correct complexity measure is even more elusive. The study of
double descent phenomenon is an active research topic.
8
The figure is reproduced from Figure 1 of Nakkiran et al. [2020]. Similar phenomenon
are also observed in Hastie et al. [2022], Mei and Montanari [2022]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
114
Figure 8.12:
Left:
The double descent phenomenon, where the number of pa-
rameters is used as the model complexity.
Middle:
The norm of the learned
model is peaked around
n
≈
d
.
Right:
The test error against the norm of
the learnt model. The color bar indicate the number of parameters and the
arrows indicates the direction of increasing model size.
Their relationship
are closer to the convention wisdom than to a double descent.
Setup:
We
consider a linear regression with a fixed dataset of size
n
= 500
.
The input
x
is a random ReLU feature on Fashion-MNIST, and output
y
∈
R
10
is the
one-hot label. This is the same setting as in Section 5.2 of Nakkiran et al.
[2020].
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
115
8.3
Sample
complexity
bounds
(optional
readings)
8.3.1
Preliminaries
In this set of notes, we begin our foray into learning theory.
Apart from
being interesting and enlightening in its own right, this discussion will also
help us hone our intuitions and derive rules of thumb about how to best
apply learning algorithms in different settings. We will also seek to answer
a few questions: First, can we make formal the bias/variance tradeoff that
was just discussed?
This will also eventually lead us to talk about model
selection methods, which can, for instance, automatically decide what order
polynomial to fit to a training set.
Second, in machine learning it’s really
generalization error that we care about, but most learning algorithms fit their
models to the training set. Why should doing well on the training set tell us
anything about generalization error? Specifically, can we relate error on the
training set to generalization error? Third and finally, are there conditions
under which we can actually prove that learning algorithms will work well?
We start with two simple but very useful lemmas.
Lemma.
(The union bound). Let
A
1
, A
2
, . . . , A
k
be
k
different events (that
may not be independent). Then
P
(
A
1
∪ · · · ∪
A
k
)
≤
P
(
A
1
) +
. . .
+
P
(
A
k
)
.
In probability theory, the union bound is usually stated as an axiom
(and thus we won’t try to prove it), but it also makes intuitive sense: The
probability of any one of
k
events happening is at most the sum of the
probabilities of the
k
different events.
Lemma.
(Hoeffding inequality) Let
Z
1
, . . . , Z
n
be
n
independent and iden-
tically distributed (iid) random variables drawn from a Bernoulli(
φ
) distri-
bution. I.e.,
P
(
Z
i
= 1) =
φ
, and
P
(
Z
i
= 0) = 1
-
φ
. Let
ˆ
φ
= (1
/n
)
∑
n
i
=1
Z
i
be the mean of these random variables, and let any
γ >
0 be fixed. Then
P
(
|
φ
-
ˆ
φ
|
> γ
)
≤
2 exp(
-
2
γ
2
n
)
This lemma (which in learning theory is also called the
Chernoff bound
)
says that if we take
ˆ
φ
—the average of
n
Bernoulli(
φ
) random variables—to
be our estimate of
φ
, then the probability of our being far from the true value
is small, so long as
n
is large. Another way of saying this is that if you have
a biased coin whose chance of landing on heads is
φ
, then if you toss it
n
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
116
times and calculate the fraction of times that it came up heads, that will be
a good estimate of
φ
with high probability (if
n
is large).
Using just these two lemmas, we will be able to prove some of the deepest
and most important results in learning theory.
To simplify our exposition, let’s restrict our attention to binary classifica-
tion in which the labels are
y
∈ {
0
,
1
}
. Everything we’ll say here generalizes
to other problems, including regression and multi-class classification.
We assume we are given a training set
S
=
{
(
x
(
i
)
, y
(
i
)
);
i
= 1
, . . . , n
}
of size
n
, where the training examples (
x
(
i
)
, y
(
i
)
) are drawn iid from some probability
distribution
D
. For a hypothesis
h
, we define the
training error
(also called
the
empirical risk
or
empirical error
in learning theory) to be
ˆ
ε
(
h
) =
1
n
n
X
i
=1
1
{
h
(
x
(
i
)
)
6
=
y
(
i
)
}
.
This is just the fraction of training examples that
h
misclassifies. When we
want to make explicit the dependence of ˆ
ε
(
h
) on the training set
S
, we may
also write this a ˆ
ε
S
(
h
). We also define the generalization error to be
ε
(
h
) =
P
(
x,y
)
∼D
(
h
(
x
)
6
=
y
)
.
I.e. this is the probability that, if we now draw a new example (
x, y
) from
the distribution
D
,
h
will misclassify it.
Note that we have assumed that the training data was drawn from the
same
distribution
D
with which we’re going to evaluate our hypotheses (in
the definition of generalization error). This is sometimes also referred to as
one of the
PAC
assumptions.
9
Consider the setting of linear classification, and let
h
θ
(
x
) = 1
{
θ
T
x
≥
0
}
.
What’s a reasonable way of fitting the parameters
θ
? One approach is to try
to minimize the training error, and pick
ˆ
θ
= arg min
θ
ˆ
ε
(
h
θ
)
.
We call this process
empirical risk minimization
(ERM), and the resulting
hypothesis output by the learning algorithm is
ˆ
h
=
h
ˆ
θ
. We think of ERM
as the most “basic” learning algorithm, and it will be this algorithm that we
9
PAC stands for “probably approximately correct,” which is a framework and set of
assumptions under which numerous results on learning theory were proved. Of these, the
assumption of training and testing on the same distribution, and the assumption of the
independently drawn training examples, were the most important.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
117
focus on in these notes. (Algorithms such as logistic regression can also be
viewed as approximations to empirical risk minimization.)
In our study of learning theory, it will be useful to abstract away from
the specific parameterization of hypotheses and from issues such as whether
we’re using a linear classifier. We define the
hypothesis class
H
used by a
learning algorithm to be the set of all classifiers considered by it. For linear
classification,
H
=
{
h
θ
:
h
θ
(
x
) = 1
{
θ
T
x
≥
0
}
, θ
∈
R
d
+1
}
is thus the set of
all classifiers over
X
(the domain of the inputs) where the decision boundary
is linear. More broadly, if we were studying, say, neural networks, then we
could let
H
be the set of all classifiers representable by some neural network
architecture.
Empirical risk minimization can now be thought of as a minimization over
the class of functions
H
, in which the learning algorithm picks the hypothesis:
ˆ
h
= arg min
h
∈H
ˆ
ε
(
h
)
8.3.2
The case of finite
H
Let’s start by considering a learning problem in which we have a finite hy-
pothesis class
H
=
{
h
1
, . . . , h
k
}
consisting of
k
hypotheses. Thus,
H
is just a
set of
k
functions mapping from
X
to
{
0
,
1
}
, and empirical risk minimization
selects
ˆ
h
to be whichever of these
k
functions has the smallest training error.
We would like to give guarantees on the generalization error of
ˆ
h
. Our
strategy for doing so will be in two parts: First, we will show that ˆ
ε
(
h
) is a
reliable estimate of
ε
(
h
) for all
h
. Second, we will show that this implies an
upper-bound on the generalization error of
ˆ
h
.
Take any one, fixed,
h
i
∈ H
.
Consider a Bernoulli random variable
Z
whose distribution is defined as follows. We’re going to sample (
x, y
)
∼ D
.
Then, we set
Z
= 1
{
h
i
(
x
)
6
=
y
}
.
I.e., we’re going to draw one example,
and let
Z
indicate whether
h
i
misclassifies it. Similarly, we also define
Z
j
=
1
{
h
i
(
x
(
j
)
)
6
=
y
(
j
)
}
. Since our training set was drawn iid from
D
,
Z
and the
Z
j
’s have the same distribution.
We see that the misclassification probability on a randomly drawn
example—that is,
ε
(
h
)—is exactly the expected value of
Z
(and
Z
j
). More-
over, the training error can be written
ˆ
ε
(
h
i
) =
1
n
n
X
j
=1
Z
j
.
Thus, ˆ
ε
(
h
i
) is exactly the mean of the
n
random variables
Z
j
that are drawn
iid from a Bernoulli distribution with mean
ε
(
h
i
). Hence, we can apply the
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
118
Hoeffding inequality, and obtain
P
(
|
ε
(
h
i
)
-
ˆ
ε
(
h
i
)
|
> γ
)
≤
2 exp(
-
2
γ
2
n
)
.
This shows that, for our particular
h
i
, training error will be close to
generalization error with high probability, assuming
n
is large. But we don’t
just want to guarantee that
ε
(
h
i
) will be close to ˆ
ε
(
h
i
) (with high probability)
for just only one particular
h
i
.
We want to prove that this will be true
simultaneously for
all
h
∈ H
. To do so, let
A
i
denote the event that
|
ε
(
h
i
)
-
ˆ
ε
(
h
i
)
|
> γ
. We’ve already shown that, for any particular
A
i
, it holds true
that
P
(
A
i
)
≤
2 exp(
-
2
γ
2
n
). Thus, using the union bound, we have that
P
(
∃
h
∈ H
.
|
ε
(
h
i
)
-
ˆ
ε
(
h
i
)
|
> γ
)
=
P
(
A
1
∪ · · · ∪
A
k
)
≤
k
X
i
=1
P
(
A
i
)
≤
k
X
i
=1
2 exp(
-
2
γ
2
n
)
=
2
k
exp(
-
2
γ
2
n
)
If we subtract both sides from 1, we find that
P
(
¬∃
h
∈ H
.
|
ε
(
h
i
)
-
ˆ
ε
(
h
i
)
|
> γ
)
=
P
(
∀
h
∈ H
.
|
ε
(
h
i
)
-
ˆ
ε
(
h
i
)
| ≤
γ
)
≥
1
-
2
k
exp(
-
2
γ
2
n
)
(The
“
¬
”
symbol
means
“not.”)
So,
with
probability
at
least
1
-
2
k
exp(
-
2
γ
2
n
), we have that
ε
(
h
) will be within
γ
of ˆ
ε
(
h
) for all
h
∈ H
.
This is called a
uniform convergence
result, because this is a bound that
holds simultaneously for all (as opposed to just one)
h
∈ H
.
In the discussion above, what we did was, for particular values of
n
and
γ
, give a bound on the probability that for some
h
∈ H
,
|
ε
(
h
)
-
ˆ
ε
(
h
)
|
> γ
.
There are three quantities of interest here:
n
,
γ
, and the probability of error;
we can bound either one in terms of the other two.
For instance, we can ask the following question: Given
γ
and some
δ >
0,
how large must
n
be before we can guarantee that with probability at least
1
-
δ
, training error will be within
γ
of generalization error?
By setting
δ
= 2
k
exp(
-
2
γ
2
n
) and solving for
n
, [you should convince yourself this is
the right thing to do!], we find that if
n
≥
1
2
γ
2
log
2
k
δ
,
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
119
then with probability at least 1
-
δ
, we have that
|
ε
(
h
)
-
ˆ
ε
(
h
)
| ≤
γ
for all
h
∈ H
. (Equivalently, this shows that the probability that
|
ε
(
h
)
-
ˆ
ε
(
h
)
|
> γ
for some
h
∈ H
is at most
δ
.)
This bound tells us how many training
examples we need in order make a guarantee. The training set size
n
that
a certain method or algorithm requires in order to achieve a certain level of
performance is also called the algorithm’s
sample complexity
.
The key property of the bound above is that the number of training
examples needed to make this guarantee is only
logarithmic
in
k
, the number
of hypotheses in
H
. This will be important later.
Similarly, we can also hold
n
and
δ
fixed and solve for
γ
in the previous
equation, and show [again, convince yourself that this is right!]
that with
probability 1
-
δ
, we have that for all
h
∈ H
,
|
ˆ
ε
(
h
)
-
ε
(
h
)
| ≤
r
1
2
n
log
2
k
δ
.
Now, let’s assume that uniform convergence holds, i.e., that
|
ε
(
h
)
-
ˆ
ε
(
h
)
| ≤
γ
for all
h
∈ H
. What can we prove about the generalization of our learning
algorithm that picked
ˆ
h
= arg min
h
∈H
ˆ
ε
(
h
)?
Define
h
*
= arg min
h
∈H
ε
(
h
) to be the best possible hypothesis in
H
. Note
that
h
*
is the best that we could possibly do given that we are using
H
, so
it makes sense to compare our performance to that of
h
*
. We have:
ε
(
ˆ
h
)
≤
ˆ
ε
(
ˆ
h
) +
γ
≤
ˆ
ε
(
h
*
) +
γ
≤
ε
(
h
*
) + 2
γ
The first line used the fact that
|
ε
(
ˆ
h
)
-
ˆ
ε
(
ˆ
h
)
| ≤
γ
(by our uniform convergence
assumption). The second used the fact that
ˆ
h
was chosen to minimize ˆ
ε
(
h
),
and hence ˆ
ε
(
ˆ
h
)
≤
ˆ
ε
(
h
) for all
h
, and in particular ˆ
ε
(
ˆ
h
)
≤
ˆ
ε
(
h
*
). The third
line used the uniform convergence assumption again, to show that ˆ
ε
(
h
*
)
≤
ε
(
h
*
) +
γ
.
So, what we’ve shown is the following: If uniform convergence
occurs, then the generalization error of
ˆ
h
is at most 2
γ
worse than the best
possible hypothesis in
H
!
Let’s put all this together into a theorem.
Theorem.
Let
|H|
=
k
, and let any
n, δ
be fixed. Then with probability at
least 1
-
δ
, we have that
ε
(
ˆ
h
)
≤
min
h
∈H
ε
(
h
)
+ 2
r
1
2
n
log
2
k
δ
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
120
This is proved by letting
γ
equal the
√
·
term, using our previous argu-
ment that uniform convergence occurs with probability at least 1
-
δ
, and
then noting that uniform convergence implies
ε
(
h
) is at most 2
γ
higher than
ε
(
h
*
) = min
h
∈H
ε
(
h
) (as we showed previously).
This also quantifies what we were saying previously saying about the
bias/variance tradeoff in model selection. Specifically, suppose we have some
hypothesis class
H
, and are considering switching to some much larger hy-
pothesis class
H
0
⊇ H
.
If we switch to
H
0
, then the first term min
h
ε
(
h
)
can only decrease (since we’d then be taking a min over a larger set of func-
tions).
Hence, by learning using a larger hypothesis class, our “bias” can
only decrease. However, if k increases, then the second 2
√
·
term would also
increase. This increase corresponds to our “variance” increasing when we use
a larger hypothesis class.
By holding
γ
and
δ
fixed and solving for
n
like we did before, we can also
obtain the following sample complexity bound:
Corollary.
Let
|H|
=
k
, and let any
δ, γ
be fixed.
Then for
ε
(
ˆ
h
)
≤
min
h
∈H
ε
(
h
) + 2
γ
to hold with probability at least 1
-
δ
, it suffices that
n
≥
1
2
γ
2
log
2
k
δ
=
O
1
γ
2
log
k
δ
,
8.3.3
The case of infinite
H
We have proved some useful theorems for the case of finite hypothesis classes.
But many hypothesis classes, including any parameterized by real numbers
(as in linear classification) actually contain an infinite number of functions.
Can we prove similar results for this setting?
Let’s start by going through something that is
not
the “right” argument.
Better and more general arguments exist
, but this will be useful for honing
our intuitions about the domain.
Suppose we have an
H
that is parameterized by
d
real numbers. Since we
are using a computer to represent real numbers, and IEEE double-precision
floating point (
double
’s in C) uses 64 bits to represent a floating point num-
ber, this means that our learning algorithm, assuming we’re using double-
precision floating point, is parameterized by 64
d
bits. Thus, our hypothesis
class really consists of at most
k
= 2
64
d
different hypotheses. From the Corol-
lary at the end of the previous section, we therefore find that, to guarantee
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
121
ε
(
ˆ
h
)
≤
ε
(
h
*
)+2
γ
, with to hold with probability at least 1
-
δ
, it suffices that
n
≥
O
1
γ
2
log
2
64
d
δ
=
O
d
γ
2
log
1
δ
=
O
γ,δ
(
d
). (The
γ, δ
subscripts indicate
that the last big-
O
is hiding constants that may depend on
γ
and
δ
.) Thus,
the number of training examples needed is at most
linear
in the parameters
of the model.
The fact that we relied on 64-bit floating point makes this argument not
entirely satisfying, but the conclusion is nonetheless roughly correct: If what
we try to do is minimize training error, then in order to learn “well” using a
hypothesis class that has
d
parameters, generally we’re going to need on the
order of a linear number of training examples in
d
.
(At this point, it’s worth noting that these results were proved for an al-
gorithm that uses empirical risk minimization. Thus, while the linear depen-
dence of sample complexity on
d
does generally hold for most discriminative
learning algorithms that try to minimize training error or some approxima-
tion to training error, these conclusions do not always apply as readily to
discriminative learning algorithms.
Giving good theoretical guarantees on
many non-ERM learning algorithms is still an area of active research.)
The other part of our previous argument that’s slightly unsatisfying is
that it relies on the parameterization of
H
. Intuitively, this doesn’t seem like
it should matter: We had written the class of linear classifiers as
h
θ
(
x
) =
1
{
θ
0
+
θ
1
x
1
+
· · ·
θ
d
x
d
≥
0
}
, with
n
+ 1 parameters
θ
0
, . . . , θ
d
. But it could
also be written
h
u,v
(
x
) = 1
{
(
u
2
0
-
v
2
0
) + (
u
2
1
-
v
2
1
)
x
1
+
· · ·
(
u
2
d
-
v
2
d
)
x
d
≥
0
}
with 2
d
+ 2 parameters
u
i
, v
i
. Yet, both of these are just defining the same
H
: The set of linear classifiers in
d
dimensions.
To derive a more satisfying argument, let’s define a few more things.
Given a set
S
=
{
x
(
i
)
, . . . , x
(
D
)
}
(no relation to the training set) of points
x
(
i
)
∈ X
, we say that
H
shatters
S
if
H
can realize any labeling on
S
.
I.e., if for any set of labels
{
y
(1)
, . . . , y
(
D
)
}
, there exists some
h
∈ H
so that
h
(
x
(
i
)
) =
y
(
i
)
for all
i
= 1
, . . .
D
.
Given a hypothesis class
H
, we then define its
Vapnik-Chervonenkis
dimension
, written VC(
H
), to be the size of the largest set that is shattered
by
H
. (If
H
can shatter arbitrarily large sets, then VC(
H
) =
∞
.)
For instance, consider the following set of three points:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
122
x
x
1
2
Can the set
H
of linear classifiers in two dimensions (
h
(
x
) = 1
{
θ
0
+
θ
1
x
1
+
θ
2
x
2
≥
0
}
) can shatter the set above? The answer is yes. Specifically, we
see that, for any of the eight possible labelings of these points, we can find a
linear classifier that obtains “zero training error” on them:
x
x
1
2
x
x
1
2
x
x
1
2
x
x
1
2
x
x
1
2
x
x
1
2
x
x
1
2
x
x
1
2
Moreover, it is possible to show that there is no set of 4 points that this
hypothesis class can shatter. Thus, the largest set that
H
can shatter is of
size 3, and hence VC(
H
) = 3.
Note that the VC dimension of
H
here is 3 even though there may be
sets of size 3 that it cannot shatter. For instance, if we had a set of three
points lying in a straight line (left figure), then there is no way to find a linear
separator for the labeling of the three points shown below (right figure):
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
123
x
x
1
2
x
x
1
2
In order words, under the definition of the VC dimension, in order to
prove that VC(
H
) is at least
D
, we need to show only that there’s at least
one
set of size
D
that
H
can shatter.
The following theorem, due to Vapnik, can then be shown. (This is, many
would argue, the most important theorem in all of learning theory.)
Theorem.
Let
H
be given, and let
D
= VC(
H
). Then with probability at
least 1
-
δ
, we have that for all
h
∈ H
,
|
ε
(
h
)
-
ˆ
ε
(
h
)
| ≤
O
r
D
n
log
n
D
+
1
n
log
1
δ
!
.
Thus, with probability at least 1
-
δ
, we also have that:
ε
(
ˆ
h
)
≤
ε
(
h
*
) +
O
r
D
n
log
n
D
+
1
n
log
1
δ
!
.
In other words, if a hypothesis class has finite VC dimension, then uniform
convergence occurs as
n
becomes large. As before, this allows us to give a
bound on
ε
(
h
) in terms of
ε
(
h
*
). We also have the following corollary:
Corollary.
For
|
ε
(
h
)
-
ˆ
ε
(
h
)
| ≤
γ
to hold for all
h
∈ H
(and hence
ε
(
ˆ
h
)
≤
ε
(
h
*
) + 2
γ
) with probability at least 1
-
δ
, it suffices that
n
=
O
γ,δ
(
D
).
In other words, the number of training examples needed to learn “well”
using
H
is linear in the VC dimension of
H
. It turns out that, for “most”
hypothesis classes, the VC dimension (assuming a “reasonable” parameter-
ization) is also roughly linear in the number of parameters.
Putting these
together, we conclude that for a given hypothesis class
H
(and for an algo-
rithm that tries to minimize training error), the number of training examples
needed to achieve generalization error close to that of the optimal classifier
is usually roughly linear in the number of parameters of
H
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Chapter 9
Regularization and model
selection
9.1
Regularization
Recall that as discussed in Section 8.1, overftting is typically a result of using
too complex models, and we need to choose a proper model complexity to
achieve the optimal bias-variance tradeoff.
When the model complexity is
measured by the number of parameters, we can vary the size of the model
(e.g., the width of a neural net). However, the correct, informative complex-
ity measure of the models can be a function of the parameters (e.g.,
‘
2
norm
of the parameters), which may not necessarily depend on the number of pa-
rameters. In such cases, we will use regularization, an important technique
in machine learning, control the model complexity and prevent overfitting.
Regularization typically involves adding an additional term, called a reg-
ularizer and denoted by
R
(
θ
) here, to the training loss/cost function:
J
λ
(
θ
) =
J
(
θ
) +
λR
(
θ
)
(9.1)
Here
J
λ
is often called the regularized loss, and
λ
≥
0 is called the regular-
ization parameter. The regularizer
R
(
θ
) is a nonnegative function (in almost
all cases). In classical methods,
R
(
θ
) is purely a function of the parameter
θ
,
but some modern approach allows
R
(
θ
) to depend on the training dataset.
1
The regularizer
R
(
θ
) is typically chosen to be some measure of the com-
plexity of the model
θ
.
Thus, when using the regularized loss, we aim to
find a model that both fit the data (a small loss
J
(
θ
)) and have a small
1
Here our notations generally omit the dependency on the training dataset for
simplicity—we write
J
(
θ
) even though it obviously needs to depend on the training dataset.
124
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
125
model complexity (a small
R
(
θ
)). The balance between the two objectives is
controlled by the regularization parameter
λ
. When
λ
= 0, the regularized
loss is equivalent to the original loss. When
λ
is a sufficiently small positive
number, minimizing the regularized loss is effectively minimizing the original
loss with the regularizer as the tie-breaker. When the regularizer is extremely
large, then the original loss is not effective (and likely the model will have a
large bias.)
The most commonly used regularization is perhaps
‘
2
regularization,
where
R
(
θ
) =
1
2
k
θ
k
2
2
.
It encourages the optimizer to find a model with
small
‘
2
norm. In deep learning, it’s oftentimes referred to as
weight de-
cay
, because gradient descent with learning rate
η
on the regularized loss
R
λ
(
θ
) is equivalent to shrinking/decaying
θ
by a scalar factor of 1
-
ηλ
and
then applying the standard gradient
θ
←
θ
-
η
∇
J
λ
(
θ
) =
θ
-
ηλθ
-
η
∇
J
(
θ
)
=
(1
-
λη
)
θ
|
{z
}
decaying weights
-
η
∇
J
(
θ
)
(9.2)
Besides encouraging simpler models, regularization can also impose in-
ductive biases or structures on the model parameters. For example, suppose
we had a prior belief that the number of non-zeros in the ground-truth model
parameters is small,
2
—which is oftentimes called sparsity of the model—, we
can impose a regularization on the number of non-zeros in
θ
, denoted by
k
θ
k
0
, to leverage such a prior belief.
Imposing additional structure of the
parameters narrows our search space and makes the complexity of the model
family smaller,—e.g., the family of sparse models can be thought of as having
lower complexity than the family of all models—, and thus tends to lead to a
better generalization. On the other hand, imposing additional structure may
risk increasing the bias. For example, if we regularize the sparsity strongly
but no sparse models can predict the label accurately, we will suffer from
large bias (analogously to the situation when we use linear models to learn
data than can only be represented by quadratic functions in Section 8.1.)
The sparsity of the parameters is not a continuous function of the param-
eters, and thus we cannot optimize it with (stochastic) gradient descent. A
common relaxation is to use
R
(
θ
) =
k
θ
k
1
as a continuous surrogate.
3
2
For linear models, this means the model just uses a few coordinates of the inputs to
make an accurate prediction.
3
There has been a rich line of theoretical work that explains why
k
θ
k
1
is a good sur-
rogate for encouraging sparsity, but it’s beyond the scope of this course. An intuition is:
assuming the parameter is on the unit sphere, the parameter with smallest
‘
1
norm also
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
126
The
R
(
θ
) =
k
θ
k
1
(also called LASSO) and
R
(
θ
) =
1
2
k
θ
k
2
2
are perhaps
among the most commonly used regularizers for linear models. Other norm
and powers of norms are sometimes also used. The
‘
2
norm regularization is
much more commonly used with kernel methods because
‘
1
regularization is
typically not compatible with the kernel trick (the optimal solution cannot
be written as functions of inner products of features.)
In deep learning, the most commonly used regularizer is
‘
2
regularization
or weight decay. Other common ones include dropout, data augmentation,
regularizing the spectral norm of the weight matrices, and regularizing the
Lipschitzness of the model, etc.
Regularization in deep learning is an ac-
tive research area, and it’s known that there is another implicit source of
regularization, as discussed in the next section.
9.2
Implicit regularization effect
The implicit regularization effect of optimizers, or implicit bias or algorithmic
regularization, is a new concept/phenomenon observed in the deep learning
era. It largely refers to that the optimizers can implicitly impose structures
on parameters beyond what has been imposed by the regularized loss.
In most classical settings, the loss or regularized loss has a unique global
minimum, and thus any reasonable optimizer should converge to that global
minimum and cannot impose any additional preferences. However, in deep
learning, oftentimes the loss or regularized loss has more than one (approx-
imate) global minima, and difference optimizers may converge to different
global minima. Though these global minima have the same or similar train-
ing losses, they may be of different nature and have dramatically different
generalization performance. See Figures 9.1 and 9.2 and its caption for an
illustration and some experiment results. For example, it’s possible that one
global minimum gives a much more Lipschitz or sparse model than others
and thus has a better test error. It turns out that many commonly-used op-
timizers (or their components) prefer or bias towards finding global minima
of certain properties, leading to a better test performance.
happen to be the sparsest parameter with only 1 non-zero coordinate. Thus, sparsity and
‘
1
norm gives the same extremal points to some extent.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
127
θ
loss
Figure 9.1: An Illustration that different global minima of the training loss
can have different test performance.
Figure 9.2:
Left:
Performance of neural networks trained by two different
learning rates schedules on the CIFAR-10 dataset.
Although both exper-
iments used exactly the same regularized losses and the optimizers fit the
training data perfectly, the models’ generalization performance differ much.
Right:
On a different synthetic dataset, optimizers with different initializa-
tions have the same training error but different generalization performance.
4
In summary, the takehome message here is that the choice of optimizer
does not only affect minimizing the training loss, but also imposes implicit
regularization and affects the generalization of the model. Even if your cur-
rent optimizer already converges to a small training error perfectly, you may
still need to tune your optimizer for a better generalization, .
4
The setting is the same as in Woodworth et al. [2020], HaoChen et al. [2020]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
128
One may wonder which components of the optimizers bias towards what
type of global minima and what type of global minima may generalize bet-
ter.
These are open questions that researchers are actively investigating.
Empirical and theoretical research have offered some clues and heuristics.
In many (but definitely far from all) situations, among those setting where
optimization can succeed in minimizing the training loss, the use of larger
initial learning rate, smaller initialization, smaller batch size, and momen-
tum appears to help with biasing towards more generalizable solutions. A
conjecture (that can be proven in certain simplified case) is that stochas-
ticity in the optimization process help the optimizer to find flatter global
minima (global minima where the curvature of the loss is small), and flat
global minima tend to give more Lipschitz models and better generalization.
Characterizing the implicit regularization effect formally is still a challenging
open research question.
9.3
Model selection via cross validation
Suppose we are trying select among several different models for a learning
problem.
For instance, we might be using a polynomial regression model
h
θ
(
x
) =
g
(
θ
0
+
θ
1
x
+
θ
2
x
2
+
· · ·
+
θ
k
x
k
), and wish to decide if
k
should be
0, 1, . . . , or 10. How can we automatically select a model that represents
a good tradeoff between the twin evils of bias and variance
5
? Alternatively,
suppose we want to automatically choose the bandwidth parameter
τ
for
locally weighted regression, or the parameter
C
for our
‘
1
-regularized SVM.
How can we do that?
For the sake of concreteness, in these notes we assume we have some
finite set of models
M
=
{
M
1
, . . . , M
d
}
that we’re trying to select among.
For instance, in our first example above, the model
M
i
would be an
i
-th
degree polynomial regression model.
(The generalization to infinite
M
is
not hard.
6
) Alternatively, if we are trying to decide between using an SVM,
a neural network or logistic regression, then
M
may contain these models.
5
Given that we said in the previous set of notes that bias and variance are two very
different beasts, some readers may be wondering if we should be calling them “twin” evils
here.
Perhaps it’d be better to think of them as non-identical twins.
The phrase “the
fraternal twin evils of bias and variance” doesn’t have the same ring to it, though.
6
If we are trying to choose from an infinite set of models, say corresponding to the
possible values of the bandwidth
τ
∈
R
+
, we may discretize
τ
and consider only a finite
number of possible values for it. More generally, most of the algorithms described here
can all be viewed as performing optimization search in the space of models, and we can
perform this search over infinite model classes as well.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
129
Cross validation.
Lets suppose we are, as usual, given a training set
S
.
Given what we know about empirical risk minimization, here’s what might
initially seem like a algorithm, resulting from using empirical risk minimiza-
tion for model selection:
1. Train each model
M
i
on
S
, to get some hypothesis
h
i
.
2. Pick the hypotheses with the smallest training error.
This algorithm does
not
work. Consider choosing the degree of a poly-
nomial. The higher the degree of the polynomial, the better it will fit the
training set
S
, and thus the lower the training error. Hence, this method will
always select a high-variance, high-degree polynomial model, which we saw
previously is often poor choice.
Here’s an algorithm that works better. In
hold-out cross validation
(also called
simple cross validation
), we do the following:
1. Randomly split
S
into
S
train
(say, 70% of the data) and
S
cv
(the remain-
ing 30%). Here,
S
cv
is called the hold-out cross validation set.
2. Train each model
M
i
on
S
train
only, to get some hypothesis
h
i
.
3. Select and output the hypothesis
h
i
that had the smallest error ˆ
ε
S
cv
(
h
i
)
on the hold out cross validation set. (Here ˆ
ε
S
cv
(
h
) denotes the average
error of
h
on the set of examples in
S
cv
.)
The error on the hold out
validation set is also referred to as the validation error.
By testing/validating on a set of examples
S
cv
that the models were not
trained on, we obtain a better estimate of each hypothesis
h
i
’s true general-
ization/test error. Thus, this approach is essentially picking the model with
the smallest estimated generalization/test error. The size of the validation
set depends on the total number of available examples. Usually, somewhere
between 1
/
4
-
1
/
3 of the data is used in the hold out cross validation set, and
30% is a typical choice. However, when the total dataset is huge, validation
set can be a smaller fraction of the total examples as long as the absolute
number of validation examples is decent.
For example, for the ImageNet
dataset that has about 1M training images, the validation set is sometimes
set to be 50K images, which is only about 5% of the total examples.
Optionally, step 3 in the algorithm may also be replaced with selecting
the model
M
i
according to arg min
i
ˆ
ε
S
cv
(
h
i
), and then retraining
M
i
on the
entire training set
S
. (This is often a good idea, with one exception being
learning algorithms that are be very sensitive to perturbations of the initial
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
130
conditions and/or data. For these methods,
M
i
doing well on
S
train
does not
necessarily mean it will also do well on
S
cv
, and it might be better to forgo
this retraining step.)
The disadvantage of using hold out cross validation is that it “wastes”
about 30% of the data. Even if we were to take the optional step of retraining
the model on the entire training set, it’s still as if we’re trying to find a good
model for a learning problem in which we had 0
.
7
n
training examples, rather
than
n
training examples, since we’re testing models that were trained on
only 0
.
7
n
examples each time. While this is fine if data is abundant and/or
cheap, in learning problems in which data is scarce (consider a problem with
n
= 20, say), we’d like to do something better.
Here is a method, called
k
-fold cross validation
, that holds out less
data each time:
1. Randomly split
S
into
k
disjoint subsets of
m/k
training examples each.
Lets call these subsets
S
1
, . . . , S
k
.
2. For each model
M
i
, we evaluate it as follows:
For
j
= 1
, . . . , k
Train the model
M
i
on
S
1
∪ · · · ∪
S
j
-
1
∪
S
j
+1
∪ · · ·
S
k
(i.e., train
on all the data except
S
j
) to get some hypothesis
h
ij
.
Test the hypothesis
h
ij
on
S
j
, to get ˆ
ε
S
j
(
h
ij
).
The estimated generalization error of model
M
i
is then calculated
as the average of the ˆ
ε
S
j
(
h
ij
)’s (averaged over
j
).
3. Pick the model
M
i
with the lowest estimated generalization error, and
retrain that model on the entire training set
S
. The resulting hypothesis
is then output as our final answer.
A typical choice for the number of folds to use here would be
k
= 10.
While the fraction of data held out each time is now 1
/k
—much smaller
than before—this procedure may also be more computationally expensive
than hold-out cross validation, since we now need train to each model
k
times.
While
k
= 10 is a commonly used choice, in problems in which data is
really scarce, sometimes we will use the extreme choice of
k
=
m
in order
to leave out as little data as possible each time. In this setting, we would
repeatedly train on all but one of the training examples in
S
, and test on that
held-out example. The resulting
m
=
k
errors are then averaged together to
obtain our estimate of the generalization error of a model. This method has
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
131
its own name; since we’re holding out one training example at a time, this
method is called
leave-one-out cross validation.
Finally, even though we have described the different versions of cross vali-
dation as methods for selecting a model, they can also be used more simply to
evaluate a
single
model or algorithm. For example, if you have implemented
some learning algorithm and want to estimate how well it performs for your
application (or if you have invented a novel learning algorithm and want to
report in a technical paper how well it performs on various test sets), cross
validation would give a reasonable way of doing so.
9.4
Bayesian statistics and regularization
In this section, we will talk about one more tool in our arsenal for our battle
against overfitting.
At the beginning of the quarter, we talked about parameter fitting using
maximum likelihood estimation (MLE), and chose our parameters according
to
θ
MLE
= arg max
θ
n
Y
i
=1
p
(
y
(
i
)
|
x
(
i
)
;
θ
)
.
Throughout our subsequent discussions, we viewed
θ
as an unknown param-
eter of the world. This view of the
θ
as being
constant-valued but unknown
is taken in
frequentist
statistics. In the frequentist this view of the world,
θ
is not random—it just happens to be unknown—and it’s our job to come up
with statistical procedures (such as maximum likelihood) to try to estimate
this parameter.
An alternative way to approach our parameter estimation problems is to
take the
Bayesian
view of the world, and think of
θ
as being a
random
variable
whose value is unknown.
In this approach, we would specify a
prior distribution
p
(
θ
) on
θ
that expresses our “prior beliefs” about the
parameters. Given a training set
S
=
{
(
x
(
i
)
, y
(
i
)
)
}
n
i
=1
, when we are asked to
make a prediction on a new value of
x
, we can then compute the posterior
distribution on the parameters
p
(
θ
|
S
)
=
p
(
S
|
θ
)
p
(
θ
)
p
(
S
)
=
(Q
n
i
=1
p
(
y
(
i
)
|
x
(
i
)
, θ
)
)
p
(
θ
)
R
θ
(
Q
n
i
=1
p
(
y
(
i
)
|
x
(
i
)
, θ
)
p
(
θ
))
dθ
(9.3)
In the equation above,
p
(
y
(
i
)
|
x
(
i
)
, θ
) comes from whatever model you’re using
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
132
for your learning problem. For example, if you are using Bayesian logistic re-
gression, then you might choose
p
(
y
(
i
)
|
x
(
i
)
, θ
) =
h
θ
(
x
(
i
)
)
y
(
i
)
(1
-
h
θ
(
x
(
i
)
))
(1
-
y
(
i
)
)
,
where
h
θ
(
x
(
i
)
) = 1
/
(1 + exp(
-
θ
T
x
(
i
)
)).
7
When we are given a new test example
x
and asked to make it prediction
on it, we can compute our posterior distribution on the class label using the
posterior distribution on
θ
:
p
(
y
|
x, S
) =
Z
θ
p
(
y
|
x, θ
)
p
(
θ
|
S
)
dθ
(9.4)
In the equation above,
p
(
θ
|
S
) comes from Equation (9.3). Thus, for example,
if the goal is to the predict the expected value of
y
given
x
, then we would
output
8
E[
y
|
x, S
] =
Z
y
yp
(
y
|
x, S
)
dy
The procedure that we’ve outlined here can be thought of as doing “fully
Bayesian” prediction, where our prediction is computed by taking an average
with respect to the posterior
p
(
θ
|
S
) over
θ
. Unfortunately, in general it is
computationally very difficult to compute this posterior distribution. This is
because it requires taking integrals over the (usually high-dimensional)
θ
as
in Equation (9.3), and this typically cannot be done in closed-form.
Thus, in practice we will instead approximate the posterior distribution
for
θ
. One common approximation is to replace our posterior distribution for
θ
(as in Equation 9.4) with a single point estimate. The
MAP (maximum
a posteriori)
estimate for
θ
is given by
θ
MAP
= arg max
θ
n
Y
i
=1
p
(
y
(
i
)
|
x
(
i
)
, θ
)
p
(
θ
)
.
(9.5)
Note that this is the same formulas as for the MLE (maximum likelihood)
estimate for
θ
, except for the prior
p
(
θ
) term at the end.
In practical applications, a common choice for the prior
p
(
θ
) is to assume
that
θ
∼ N
(0
, τ
2
I
). Using this choice of prior, the fitted parameters
θ
MAP
will
have smaller norm than that selected by maximum likelihood. In practice,
this causes the Bayesian MAP estimate to be less susceptible to overfitting
than the ML estimate of the parameters.
For example, Bayesian logistic
regression turns out to be an effective algorithm for text classification, even
though in text classification we usually have
d
n
.
7
Since we are now viewing
θ
as a random variable, it is okay to condition on it value,
and write “
p
(
y
|
x, θ
)” instead of “
p
(
y
|
x
;
θ
).”
8
The integral below would be replaced by a summation if
y
is discrete-valued.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Bibliography
Mikhail Belkin, Daniel Hsu, Siyuan Ma, and Soumik Mandal. Reconciling
modern machine-learning practice and the classical bias–variance trade-
off.
Proceedings of the National Academy of Sciences
, 116(32):15849–15854,
2019.
Mikhail Belkin, Daniel Hsu, and Ji Xu. Two models of double descent for
weak features.
SIAM Journal on Mathematics of Data Science
, 2(4):1167–
1180, 2020.
Jeff Z HaoChen, Colin Wei, Jason D Lee, and Tengyu Ma. Shape matters:
Understanding the implicit bias of the noise covariance.
arXiv preprint
arXiv:2006.08680
, 2020.
Trevor Hastie, Andrea Montanari, Saharon Rosset, and Ryan J Tibshirani.
Surprises in high-dimensional ridgeless least squares interpolation. 2019.
Trevor Hastie, Andrea Montanari, Saharon Rosset, and Ryan J Tibshirani.
Surprises in high-dimensional ridgeless least squares interpolation.
The
Annals of Statistics
, 50(2):949–986, 2022.
Gareth James, Daniela Witten, Trevor Hastie, and Robert Tibshirani.
An
introduction to statistical learning, second edition
, volume 112. Springer,
2021.
Song Mei and Andrea Montanari. The generalization error of random features
regression: Precise asymptotics and the double descent curve.
Communi-
cations on Pure and Applied Mathematics
, 75(4):667–766, 2022.
Preetum Nakkiran. More data can hurt for linear regression: Sample-wise
double descent. 2019.
Preetum Nakkiran, Prayaag Venkat, Sham Kakade, and Tengyu Ma. Optimal
regularization can mitigate double descent. 2020.
133
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
134
Manfred Opper. Statistical mechanics of learning: Generalization.
The hand-
book of brain theory and neural networks
, pages 922–925, 1995.
Manfred Opper. Learning to generalize.
Frontiers of Life
, 3(part 2):763–775,
2001.
Blake Woodworth, Suriya Gunasekar, Jason D Lee, Edward Moroshko, Pe-
dro Savarese, Itay Golan, Daniel Soudry, and Nathan Srebro. Kernel and
rich regimes in overparametrized models.
arXiv preprint arXiv:2002.09277
,
2020.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Documents
Recommended textbooks for you

Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

Fundamentals of Information Systems
Computer Science
ISBN:9781337097536
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781285867168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781305971776
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Recommended textbooks for you
- Fundamentals of Information SystemsComputer ScienceISBN:9781305082168Author:Ralph Stair, George ReynoldsPublisher:Cengage LearningFundamentals of Information SystemsComputer ScienceISBN:9781337097536Author:Ralph Stair, George ReynoldsPublisher:Cengage LearningPrinciples of Information Systems (MindTap Course...Computer ScienceISBN:9781285867168Author:Ralph Stair, George ReynoldsPublisher:Cengage Learning
- Principles of Information Systems (MindTap Course...Computer ScienceISBN:9781305971776Author:Ralph Stair, George ReynoldsPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT

Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

Fundamentals of Information Systems
Computer Science
ISBN:9781337097536
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781285867168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781305971776
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Browse Popular Homework Q&A
Q: The officers of a high school senior class are planning to rent buses and vans for a class trip.…
Q: You have a closed square loop of wire with length 44cm and a resistance of 750Ω. If there is a…
Q: a) Find the real and imaginary parts of cosh y+i
Q: 6) Find the characteristic equation and the corresponding roots for the following ODEs and
identify…
Q: Build the following part. Report the mass in pounds. Assume all dimensions are in inches. The…
Q: a. Approximate the given quantity using Taylor polynomials with n = 3.
b. Compute the absolute error…
Q: All edges of a cube are expanding at a rate of 9 centimeters per second.
(a) How fast is the volume…
Q: Find an LU factorization for the matrix A =
-2 3
4 1
-3
0
2
3-2,
Verify that LU = A.
Q: Recycling Approximately 70% of the U.S. population recycles. According to a green survey of a random…
Q: Which equations did you use to calculate these values? Or which machinery book did this info come…
Q: 4 Fe(s) + 3 O2(g) → 2 Fe2O3(s), ΔH = -1652 kJ
(d) How much heat is released when 11.40 g Fe and 2.13…
Q: In 1999, scientists discovered a new class of black holes with masses 100 to 10,000 times the mass…
Q: Neveah surveys 94 students at random to determine the proportion of students who have attended
Mt.…
Q: The attachments of the ACL are ________________. The attachments of the PCL are ________________.…
Q: Find dy/dx using partial derivatives
cos(x-y) = xe^y
Q: urrently, Hotel California has no debt (i.e., leverage=0). The CEO of Hotel California considers…
Q: QUESTION 8
Regarding the following reaction
CO₂ (g)+H2 (g)→→CO(g)+H₂O (g)
ArH=-41.2kJ/mol
Using Le…
Q: A monoprotic weak acid, HA, is ionized according to the reaction
HA(aq) + H₂O(1) ⇒ A¯(aq) + H₂O+…
Q: What is the theoretical yield (in grams) of acetic acid, HC₂H3O2, when 1.824 g of
carbon dioxide…
Q: B
D
A
700mm
Г
1200mm
Block A is suspended from two cables. Knowing that the tension in AC is 200 N,…
Q: Find and interpret the slope of the line containing the given points.
(4,-1) and (1,3)
Select the…
Q: For the cost and price functions below, find a) the number, q, of units that produces maximum…
Q: Standard deviation of returns is often used as a measure of a mutual fund’s volatility (risk). A…
Q: Using the periodic trends, indicate which of the following atoms has the largest first ionization…
Q: Consider the following vector function.
r(t) = (4t, 1/2t^2,t^2)
(a) Find the unit tangent and unit…