A Neural Network using Raw R Language Code

I decided to spin up a neural network demo program, using raw R language code. R is a language that’s quite unlike the others I use — mostly C#, Java, Python, and JavaScript — so it’s important for me to exercise the part of my brain that uses R.

One rather confusing thing about R is that there are at least five different OOP paradigms. They are list encapsulation (LE), S3, S4, reference classes (RC), and R6. All five programming models are quite different. I decided to use the RC paradigm.

I tackled a very common problem: classifying the Iris Dataset. There are a total of 150 flower items. Each item has four predictor variables — sepal length, sepal width, petal length, petal width. The goal is to predict the Iris species, which can be setosa, versicolor, or virginica. There are 50 of each species.

I divided the 150-ite full dataset into a 120-item training set, and a 30-item test set. Then I set about to write a neural network classifier from scratch.

It took me a couple of hours, but I got a decent classifier running. The R language syntax didn’t come to me naturally, so I had to spend a lot of time in various R language online references.

I knew R was slow, but I was surprised at how slow R is. Training a 120-item test set using C# or Python takes maybe 1 second. Using R, training took about ten times as long.

Anyway, I enjoyed my trip to R World.


I have no idea why this image popped up on an Internet search for ‘R Language’

This entry was posted in Machine Learning, R Language. Bookmark the permalink.