You are on page 1of 10

Neural Network R

Create a copy of the iris data set into

irisdata <- iris

View Summary statistics of

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

Training and Validation


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:

Load the library for neural network


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
ideal <- class.ind(irisdata$species)

Train the data

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

Use the net for prediction

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