Data Scientist - Benjamin Tovar

Using Neural Networks to fit equations in R




Using Neural Networks to fit equations in R


Quoting Wikipedia:

“In machine learning and cognitive science, artificial neural networks (ANNs) are a family of statistical learning algorithms inspired by biological neural networks (the central nervous systems of animals, in particular the brain) and are used to estimate or approximate functions that can depend on a large number of inputs and are generally unknown. Artificial neural networks are generally presented as systems of interconnected “neurons” which can compute values from inputs, and are capable of machine learning as well as pattern recognition thanks to their adaptive nature.

For example, a neural network for handwriting recognition is defined by a set of input neurons which may be activated by the pixels of an input image. After being weighted and transformed by a function[disambiguation needed] (determined by the network’s designer), the activations of these neurons are then passed on to other neurons. This process is repeated until finally, an output neuron is activated. This determines which character was read.

Like other machine learning methods – systems that learn from data – neural networks have been used to solve a wide variety of tasks that are hard to solve using ordinary rule-based programming, including computer vision and speech recognition.”

In this post I will cover a very simple pipeline to fit an equation using package RSNNS in R.


The target equation to fit is defined by:



Plot function f(x):

f1After training the model, plot the training error:


Finally, plot the predicted y values along with the original values:



You can download the code of this post clicking here


Tags: , ,

Leave a comment

Your email address will not be published. Required fields are marked. *