You are on page 1of 10

Neural Network R

Create a copy of the iris data set into


irisdata
irisdata <- iris

View Summary statistics of


IRIS
Summary (irisdata)

Training and Validation Data


Break the data into training sets and
validation (test) sets.
The training set will be used to train the
neural network
The validation set will be used to
validating the efficacy of the neural net.
Iris contains 150 records.
We will use 100 for training and 50 for
validation.

Training and Validation


Data

Query the value of the above. Notice


that they are simply index numbers
that are ponters to the data and not
the data itself.

To obtain the actual data, us ethe


follwing commands:
irisdata[irisTrainData,]
irisdata[irisValData,]

Load the library for neural network


library(nnet)

The species column is in categorical


form (non-numeric).
Remember the data into a neural net
must be a value between 0 and 1.
Thus we can normalize the data to be
between 0 and 1 using the following
command
ideal <- class.ind(irisdata$species)

Train the data


We can now train the data:
irisANN = nnet(irisdata[irisTrainData,5], ideal[irisTrainData,], size=10,
softmax=TRUE)

Use the net for prediction


predict(irisANN, irisdata[irisValData,5], type="class") The new