# NOT RUN {
# Create a dataset
dataset <- iris
dataset$Petal.Length <- NULL
dataset$Petal.Width <- NULL
dataset <- dataset[dataset$Species != "versicolor",]
dataset$Code <- as.integer(dataset$Species == "virginica")
dataset <- dataset[sample(20),]
# Create the neuron
neuron <- mcCullochPitts(c(1,1), 1)
# Train the neuron, takes a while
neuron$train(dataset[,c(1,2)], dataset[,'Code', drop=FALSE], epochs = 10)
# Check the output
neuron$output(c(1,2))
# See accuracy
dataset$Calc <- sapply(1:nrow(dataset), function(x) {
as.integer(neuron$output(dataset[x,c(1,2)]))
})
length(which(dataset$Code==dataset$Calc))/nrow(dataset)
# }
Run the code above in your browser using DataLab