top of page

Neural Network in R

Machine Learning (ML) algorithms are truly fascinating. You provide the computer a data set, and the computer 'learns' and seeks patterns within the data. Then the computer makes a prediction using generic Machine Learning algorithms. There are a lot of good ML libraries in R. And today I'm going to introduce the 'neuralnet' package in R which its really helpful in fitting a neural network.

Neural network is one of my favorite ML algorithms. It gets its name from mimicking the human brain, where hundreds of thousands of neurons exist. The best way to visualize neural networks is to imagine as if they are organized in layers. Layers are made up of a number of interconnected nodes which contain an activation function. The 'input layer' presents patterns to the network, which communicates to more than one hidden layers where the actual processing is done via a system of weighted connections. The hidden layers then link to an output layer which outputs the results in the form of graphs or tables.

Here is a very simple tutorial of how to use Neural Networks in R:

I have ran a simple code written by GekkoQuant in R. The first two lines install and load the 'neuronet' package. Lines 9 and 10 create the training data set, which is divided into 'input' and 'output' (in this case, the output is simple the square root of the randomized input data.) The plotted training set:

And as we can see, the neural network works quite well in predicting our results:

bottom of page