第1回:P1-10まで

PRMLを読み始めた。
ということで最初の方の図をトレース。
ggplot脳なのでggplotでやる。

library(ggplot2)

x <- seq(0, 1, by=0.1)
t <- sin(2*pi*x) + rnorm(n=11, mean=0, sd=0.5)
M0 <- fitted(lm(t~1))
M1 <- fitted(lm(t~poly(x,1)))
M3 <- fitted(lm(t~poly(x,3)))
M9 <- fitted(lm(t~poly(x,9)))

d <- data.frame(x, t, M0, M1, M3, M9)
d <- melt(d, id.vars=c("x","t"))

png("PRML1.png", type="cairo")
ggplot(d, aes(x, t)) + geom_point()+ stat_function(fun = function(x)sin(2*pi*x), color="green") + geom_line(aes(x,value), color="red") + facet_wrap(~variable)
dev.off()