Skip to content

Instantly share code, notes, and snippets.

@JhonatanHern
Created July 5, 2019 22:11
Show Gist options
  • Save JhonatanHern/69a9738cdf5107f41d3e254fbc03ac2c to your computer and use it in GitHub Desktop.
Save JhonatanHern/69a9738cdf5107f41d3e254fbc03ac2c to your computer and use it in GitHub Desktop.
Neural network used for clasification with the iris dataset
library(neuralnet)
library(dplyr)
random.iris <- sample_frac(iris,1)
miris <- random.iris[1:105,]
testd <- random.iris[106:150,]
miris <- mutate(miris,
setosa = Species == "setosa",
versicolor = Species == "versicolor",
virginica = Species == "virginica",
)
nn <- neuralnet(
setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,
data = miris,
hidden = c(10,10),
act.fct = "logistic",
linear.output = FALSE
)
plot(nn)
Predict=compute(nn,testd)
Predict$net.result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment