#### # # train simple NNet with just one neuron nu <- 0.5 x <- matrix(c(1,0,0,1,1,0,1,0,1,1,1,1), 4, 3, byrow=T) y <- matrix(c(0,0,0,1), 4,1) w <- matrix(1,3,1) for( k in 1:1000 ) { i <- sample(4,1) j <- sample(3,1) if( w[1] + w[2]*x[i, 2] + w[3]*x[i, 3] >= 0 ) hy<-1 else hy<-0 dw <- nu*(y[i] - hy)* x[i, j] w[j] <- w[j] + dw } ### # # fit NNet for olive data library(nnet) attach(olives) on<-nnet(cbind(olives[,8], olives[,11]), olives[,2], data=olives, size=3, decay=0.0005, linout=T, skip=T, maxit=1000) table(Region, round(predict(on))) plot(linoleic, eicosenoic, col=round(predict(on)), pch=olives$Region) rast.x<- rep(seq(min(linoleic), max(linoleic),length=75), 75) rast.y<- rep(seq(min(eicosenoic), max(eicosenoic), length=75), rep(75, 75)) pred<-predict(on, newdata=cbind(rast.x, rast.y)) points(rast.x, rast.y, col=round(pred), pch="+")