M3/4S7: Solutions 8
1. This can be implemented with existing functions, but is quite inecient, since we are re-evaluating distances many more times that is
strictly necessary. In principle, this requires a nested loop (outer loop
is folds, inner loop is v
M3/4S7: Solutions 6
1.
(z ) =
ez
(1 + ez )2
and
(z )(1 (z ) =
1
1 + ez
1
1
1 + ez
=
ez
(1 + ez )2
2. Write the logistic function as
1
ez
=
1 + ez
1 + ez
then
2
ez
1 + ez
1=
2e z 1 e z
1 ez
=
1 + ez
1 + ez
3. Inputs to hidden layer nodes H (p + 1). Hidden
M3/4S7: Solutions 9
1. Might be easier to write this as a nested loop. Note (i) use of expand.grid
to specify models, and (ii) trickery to get variables names.
set.seed(1)
n <- 200
x0 <- rmvnorm(n,c(0,1,0,0),diag(1,4)
x1 <- rmvnorm(n,c(1,0,0,0),diag(1,4)
M3/4S7: Solutions 7
1. Pen and paper version
2. The plot of error rate change against f () is
The preferred tree has cp set to 0.17. This is simply a single cut across
the variables ys.
1
The specied vector would be allocated to class 1.
The error rate of
M3/4S7: Solutions 5
1. A crude way of implementing the leave-one-out procedure is as follows
kvals <- seq(3,7,by=2)
nk <- length(kvals)
n <- nrow(synth.tr)
errs <- numeric(nk)
preds <- numeric(n)
for (i in 1:nk)cfw_
for (j in 1:n)cfw_
preds[j]<- as.numeri
M3/4S7: Solutions 3
1. (a) Note rst that the question implies that i = i I, and we estimate i by the average of the variances of the variables in class
i, si , say. This gives the estimated discriminant function for the
i class
xt i t i 1
gi (x) =
i ln s
M3/4S7: Solutions 4
1.
ki
ni
and p(Ci ) =
ni V
n
we seek the posterior probability p(Ci |x),
p(x|Ci ) =
p(Ci |x) =
p(Ci )p(x|Ci )
p(x)
=
ki ni
ni V n
kj nj
K
j =1 nj V n
=
ki
K
j =1 kj
=
ki
k
2. Implement nearest neighbour. Many ways of considering this p
M3/4S7: Solutions 2
1. For minimum risk assign to class i if
K
K
ji p(Cj |x)p(x)
j =1
jk p(Cj |x)p(x) k = 1, 2, . . . , K
j =1
Substitute for ij = 1 if i = j , and ij = 0 if i = j , and we nd we no
longer need to index across i.
K
K
p(Cj |x)p(x)p(Ci |x)p