forked from asadoughi/stat-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.Rmd
39 lines (32 loc) · 997 Bytes
/
2.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
Chapter 9: Exercise 2
=====================
$(1+X_1)^2 + (2-X_2)^2 = 4$ is a circle with radius 2 and center (-1, 2).
## a
```{r 2a}
radius = 2
plot(NA, NA, type="n", xlim=c(-4,2), ylim=c(-1,5), asp=1, xlab="X1", ylab="X2")
symbols(c(-1), c(2), circles=c(radius), add=TRUE, inches=FALSE)
```
## b
```{r 2b}
radius = 2
plot(NA, NA, type="n", xlim=c(-4,2), ylim=c(-1,5), asp=1, xlab="X1", ylab="X2")
symbols(c(-1), c(2), circles=c(radius), add=TRUE, inches=FALSE)
text(c(-1), c(2), "< 4")
text(c(-4), c(2), "> 4")
```
## c
To restate the boundary, outside the circle is blue, inside and on is red.
```{r 2c}
radius = 2
plot(c(0, -1, 2, 3), c(0, 1, 2, 8), col=c("blue", "red", "blue", "blue"),
type="p", asp=1, xlab="X1", ylab="X2")
symbols(c(-1), c(2), circles=c(radius), add=TRUE, inches=FALSE)
```
## d
The decision boundary is a sum of quadratic terms when expanded.
$$
(1+X_1)^2 + (2-X_2)^2 > 4 \\
1 + 2 X_1 + X_1^2 + 4 - 4 X_2 + X_2^2 > 4 \\
5 + 2 X_1 - 4 X_2 + X_1^2 + X_2^2 > 4
$$