2-1 We are given n = 7 observations in p = 2 dimensions. For each observation, there is an associated class label. Sketch the observations.

直接將題目的點畫出來如下圖

plot(0:4,0:4,type="n",xlab="X1",ylab="X2")
points(3,4,col="red",pch=20)
points(2,2,col="red",pch=20)
points(4,4,col="red",pch=20)
points(1,4,col="red",pch=20)
points(2,1,col="blue",pch=20)
points(4,3,col="blue",pch=20)
points(4,1,col="blue",pch=20)


2-2 Sketch the optimal separating hyperplane, and provide the equation for this hyperplane.

由上面的圖可以看出可以從 (2,2)(2,1)(4,4)(4,3) 4 點中間畫出 separating hyperplane,而這 4 點剛好形成 2 條平行的線(兩點中間距離都是 1),最好的情況為有一線經過中間 (2,1.5) (4,3.5) 使得到線到兩端點的直線距離最大,可以寫成 \(X_2=X_1-0.5\) 整理成 9.1 的形式 \(-0.5+X_1-X_2=0\)

plot(0:4,0:4,type="n",xlab="X1",ylab="X2")
points(3,4,col="red",pch=20)
points(2,2,col="red",pch=20)
points(4,4,col="red",pch=20)
points(1,4,col="red",pch=20)
points(2,1,col="blue",pch=20)
points(4,3,col="blue",pch=20)
points(4,1,col="blue",pch=20)
lines(0:4,(0:4)-0.5)


2-3 Describe the classification rule for the maximal margin classifier. It should be something along the lines of “Classify to Red if \(\beta_0 +\beta_1X_1 +\beta_2X_2 > 0\), and classify to Blue otherwise.”" Provide the values for \(\beta_0\), \(\beta_1\), and \(\beta_2\).

由上題的答案可得知該 separating hyperplane 為 \(-0.5+X_1-X_2=0\),得到 \(\beta_0=-0.5, \beta_1=1, \beta_2=-1\)


2-4 On your sketch, indicate the margin for the maximal margin hyperplane.

2-5 Indicate the support vectors for the maximal margin classifier.

邊界剛好就是周圍 2點(2,2)(4,4) 2點(2,1)(4,3)的連線,而 support vector 為兩條虛線

plot(0:4,0:4,type="n",xlab="X1",ylab="X2")
points(3,4,col="red",pch=20)
points(2,2,col="red",pch=20)
points(4,4,col="red",pch=20)
points(1,4,col="red",pch=20)
points(2,1,col="blue",pch=20)
points(4,3,col="blue",pch=20)
points(4,1,col="blue",pch=20)
lines(0:4,(0:4)-0.5)
lines(0:4,(0:4)-1,lty=2)
lines(0:4,(0:4),lty=2)


2-6 Argue that a slight movement of the seventh observation would not affect the maximal margin hyperplane.

第 7 個點為 (4,1),在下圖以圓圈表示,為了簡化將一些不在 maximal margin hyperplane 上的點刪除,可以看到 (4,1) 的點只要不移到超過 (2,2)(4,4) 的虛線就不會更改 aximal margin hyperplane 的結果。

plot(0:4,0:4,type="n",xlab="X1",ylab="X2")
points(2,2,col="red",pch=20)
points(4,4,col="red",pch=20)
points(2,1,col="blue",pch=20)
points(4,3,col="blue",pch=20)
points(4,1,col="blue")
lines(0:4,(0:4)-0.5)
lines(0:4,(0:4)-1,lty=2)
lines(0:4,(0:4),lty=2)


2-7 Sketch a hyperplane that is not the optimal separating hyperplane, and provide the equation for this hyperplane.

如下圖紅線,經過 (3,2.25) (2,1.25)的線

plot(0:4,0:4,type="n",xlab="X1",ylab="X2")
points(3,4,col="red",pch=20)
points(2,2,col="red",pch=20)
points(4,4,col="red",pch=20)
points(1,4,col="red",pch=20)
points(2,1,col="blue",pch=20)
points(4,3,col="blue",pch=20)
points(4,1,col="blue",pch=20)
lines(0:4,(0:4)-0.5)
lines(0:4,(0:4)-0.75,col="red")
lines(0:4,(0:4)-1,lty=2)
lines(0:4,(0:4),lty=2)


2-8 Draw an additional observation on the plot so that the two classes are no longer separable by a hyperplane.

如下圖,在(2,4)的地方加一個藍點,就沒辦法用線性的方法來分類

plot(0:4,0:4,type="n",xlab="X1",ylab="X2")
points(3,4,col="red",pch=20)
points(2,2,col="red",pch=20)
points(4,4,col="red",pch=20)
points(1,4,col="red",pch=20)
points(2,1,col="blue",pch=20)
points(4,3,col="blue",pch=20)
points(4,1,col="blue",pch=20)
points(2,4,col="blue",pch=20)