I’ve been brushing up my R language skills so I thought I’d see if I could write neural network code from scratch. For me, implementing neural network code in some programming language is the best way to learn the language. A neural network implementation uses most of the key features of a language.
Anyway, it took a few hours but I did get a neural network classifier written in R. I used the classic Iris Data Set where the goal is to predict the species (setosa, versicolor, or virginica) of an iris flower, from four predictor variables (sepal length and width, and petal length and width).
My classifier used all 150 iris data items for training (50 of each species). The final model weights gave 96.00% accuracy (144 correct out of 150), which is decent but not great.
I used the R6 library to create a neural network class. The more I use R6, the better I like it. My neural network class has just over 300 lines of R code.
I’m not sure what, if anything, I’ll do with the R language code, but writing the code was an effective way for me to refresh myself on details of R. For programmers who work mostly with R but who aren’t familiar with neural networks, seeing an implementation in R might be an effective way to learn about neural networks.