data(iris) set.seed(4) # we take only two features and the response iris.data <- iris[1:100,c(1,2,5)] # we sample 25 points from the S and V sample.iS <- c(sample(1:50,25)) sample.iV <- c(sample(51:100,25)) # we change the response to be -1 and 1 as required by the perceptron iris.data$id <- c(rep(-1,50),rep(1,50)) # indices of iris corresponding to ... iS <- iris$Species == "setosa" iV <- iris$Species == "versicolor" # plot of points matplot(c(3.5, 8), c(1, 4.5), type= "n", xlab = "Length", ylab = "Width", main = "Petal Dimensions in Iris Blossoms") matpoints(iris.data[sample.iS,c(1)], iris.data[sample.iS,c(2)], pch = "S", col = c(2), cex=1.6,cex.main=1.6,cex.axis=1.6) matpoints(iris.data[sample.iV,c(1)], iris.data[sample.iV,c(2)], pch = "V", col = c(4),cex=1.6,cex.main=1.6,cex.axis=1.6) legend(6.8, 1.5, c(" Setosa Petals", "Versicolor Petals"), pch = "SV", col = c(2,4)) iris.data <- iris.data[sample(c(sample.iS,sample.iV)),] head(iris.data) ## perceptron algorithm