Prepare the following exercises for discussion in class on Thursday, December 1.
Decision Tree
Nearest Neighbor
Perceptron
nnet
from package nnet
, rpart
from package
rpart
, knn
from package class
, the glm
function (check example in ?predict.glm
). Look at the examples
of these methods by ?function
. nnet
uses one hidden
layer. To implement the single layer perceptron you may try to use the
following lines for stochastic gradient descent with the needed
changes:sigma <- function(w,point) { x <- c(point,1) sign(w %*% x) } w.0 <- c(runif(1),runif(1),runif(1)) w.t <- w.0 for (j in 1:1000) { i <-sample(1:50,1) # or (j-1)%%50 + 1 diff <- y[i,3] - sigma(w.t, c(x[i,1],x[i,2])) w.t <- w.t+0.2*diff * c(x[i,1],x[i,2],1) } |
Test also the batch version of gradient descent.
More data to analyse are available at UCI Machine Learning Repository.