source("perceptron.R") maxit <- 100 learn.rate <- 0.05 # load data from the file 'leftright.dat' dat0 <- read.table("leftright.dat") # randomize the order rand = sample(nrow(dat0)) dat = dat0[rand,] # put the data in vector x, and the class labels (0 or 1) in vector y in.dim <- dim(dat)[2] - 1 x <- as.matrix(dat[,1:in.dim]) y <- as.matrix((dat[,in.dim+1] == dat[1,in.dim+1]) * 1) # split the dataset splitdat <- split.data(x, y, 10) # train a perceptron model <- perceptron(splitdat$x.train, splitdat$y.train, maxit = maxit, learn.rate = learn.rate) # report results plot(1:maxit, model$errors, type="l", xlab="iter", ylab="error") #cat("train accuracy: ", compute.accuracy(model, splitdat$x.train, splitdat$y.train), "\n") cat("test accuracy: ", compute.accuracy(model, splitdat$x.test, splitdat$y.test), "\n")