solutions MANUAL FOR A First Course In Machine Learning (2Nd Edition) Exercise Solutions Simon Rogers and Mark Girolami by
K26591_SM_Cover.indd 105/04/16 3:37 pm 1 / 4
Chapter 1 EX 1.1. A high positive value ofw0and a small negative value forw1. These reflect the high intercept on thetaxis (corresponding to the theoretical time winning time at x= 0 and the small decrese in winning time over the years.
EX 1.2. The following would do the job:
- % Attributes are stored in Nx1 vector x
- % Targets are stored in Nx1 vector t
- xb = mean(x);
- tb = mean(t);
- x2b = mean(x.*x);
- xtb = mean(x.*t);
- w1 = (xtb−xt*xb)/(x2b−xbˆ2);
- w0 = tb−w1*xb;
- % Plot the data
- MultiplyingX
10 plot(x,t,'b.','markersize',25); 11 % Plot the model 12 hold on; 13 plot(x,w0+w1*x,'r','linewidth',2); EX 1.3. We need to findw T X T Xw. We’ll start withX T
T
byXgives:
X T X= w t N n=1 x 2 n1 t N n=1 xn1xn2 t N n=1 xn2xn1 t N n=1 x 2 n2
:
Multiplying this bywgives:
X T Xw= w w
t N n=1 x 2 n1 +w1 t N n=1 xn1xn2 w0 t N n=1 xn2xn1+w1 t N n=1 x 2 n2
:
1
K26591_SM_Cover.indd 505/04/16 3:37 pm 2 / 4
2CHAPTER 1.
Finally, pre-multiplying this byw T
gives:
w T X T Xw=w 0 w w
N X n=1 x 2 n1 +w1 N X n=1 xn1xn2
:
+ w1 w w
N X n=1 xn2xn1+w1 N X n=1 x 2 n2
:
=w 2
N X n=1 x 2 n1
- 2w 0w1
N X n=1 xn1xn2+w 2 1 N X n=1 x 2 n2 as required.
EX 1.4.Let’s first work outXw:
Xw= w 0x11+w1x12 w0x21+w1x22 ...w 0xN1+w1xN2 Therefore (Xw) T = [w 0x11+w1x12, w0x21+w1x22, . . . , w0xN1+w1xN2] Finally, work outw T X T
:
w T X T = [w 0x11+w1x12, w0x21+w1x22, . . . , w0xN1+w1xN2] as required.EX 1.5.Starting with 3 n xntn. The result of this is a column vector of the same size asx (2×1). Now, using the definition ofX, X T = 2 x 11, x21, . . . , xN1 x12, x22, . . . , xN2 1 (which is a 2×Nvector). Multiplying this bytgives a 2×1 vector that looks like
this:
X T t=
3 N n=1 xn1tn 3 N n=1 xn2tn / which is 3 n xntnas required. The second example,X T Xw. We already know what X T Xwis (Exercise 1.3) X T Xw=
w
3 N n=1 x 2 n1 +w1 3 N n=1 xn1xn2 w0 3 N n=1 xn2xn1+w1 3 N n=1 x 2 n2 / Now,x nx T n
is the following matrix:
x nx T n = 2 x 2 n1 xn1xn2 xn2xn1 x 2 n2 1
K26591_SM_Cover.indd 605/04/16 3:37 pm 3 / 4
3
Multiplying this bywgives:
x nx T n w= n w 0x 2 n1 +w1xn1xn2 w0xn2xn1+w1x 2 n2 y Summing over theNterms leads us to the matrix we derived previously.
EX 1.6.Code below:
1%%Women's 100m data 2%LoadallOlympicdata 3load olympics; 4%Copythenecessaryvariables
5x = female100(:,1); %Olympicyear
6t = female100(:,2); %Winningtime
7%Augmentx 8X = [repmat(1,size(x)) x]; 9%Getsolution 10w = inv(X'*X)*X'*t;
The fitted model is:
t= 40.9242−0.0151x EX 1.7.Plugging 2012 and 2016 into the above expression yields winning times of 10.5997 and 10.5394 respectively.
EX 1.8.The men’s model is:
t= 36.4165−0.0133x
The women’s model is:
t= 40.9242−0.0151x The women’s time is decreasing faster than the men’s. Therefore, the women will
be faster at the first Olympics after thexthat gives identical winning times:
40.9242−0.0151x = 36. 4165−0.0133x x= 2589 The next Olympic year after 2589 is (assuming they continue to be held every four years) is the year 2592. The winning times are the unrealistically fast 1.8580 seconds and 1.8628 seconds for women and men respectively.EX 1.9.Code below (synthdata
cv.m):
1clear all;close all; 2load synthdata 3 4%Augmentx 5X = repmat(1,size(x));
6fork = 1:4
- X = [X x.ˆk];
8end 9
K26591_SM_Cover.indd 705/04/16 3:37 pm
- / 4