forked from asadoughi/stat-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.Rmd
65 lines (54 loc) · 1.16 KB
/
3.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Chapter 9: Exercise 3
=====================
## a
```{r 3a}
x1 = c(3,2,4,1,2,4,4)
x2 = c(4,2,4,4,1,3,1)
colors = c("red", "red", "red", "red", "blue", "blue", "blue")
plot(x1,x2,col=colors,xlim=c(0,5),ylim=c(0,5))
```
## b
The maximal margin classifier has to be in between observations #2, #3 and #5, #6.
$$
(2,2), (4,4) \\
(2,1), (4,3) \\
=> (2,1.5), (4,3.5) \\
b = (3.5 - 1.5) / (4 - 2) = 1 \\
a = X_2 - X_1 = 1.5 - 2 = -0.5
$$
```{r 3b}
plot(x1,x2,col=colors,xlim=c(0,5),ylim=c(0,5))
abline(-0.5, 1)
```
## c
$0.5 - X_1 + X_2 > 0$
## d
```{r 3d}
plot(x1,x2,col=colors,xlim=c(0,5),ylim=c(0,5))
abline(-0.5, 1)
abline(-1, 1, lty=2)
abline(0, 1, lty=2)
```
## e
```{r 3e}
plot(x1,x2,col=colors,xlim=c(0,5),ylim=c(0,5))
abline(-0.5, 1)
arrows(2,1,2,1.5)
arrows(2,2,2,1.5)
arrows(4,4,4,3.5)
arrows(4,3,4,3.5)
```
## f
A slight movement of observation #7 (4,1) blue would not have an effect on the
maximal margin hyperplane since its movement would be outside of the margin.
## g
```{r 3g}
plot(x1,x2,col=colors,xlim=c(0,5),ylim=c(0,5))
abline(-0.8, 1)
```
$-0.8 - X_1 + X_2 > 0$
## h
```{r 3h}
plot(x1,x2,col=colors,xlim=c(0,5),ylim=c(0,5))
points(c(4), c(2), col=c("red"))
```