NeuralNetTools 1.0.0 now on CRAN
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
After successfully navigating the perilous path of CRAN submission, I’m pleased to announce that NeuralNetTools is now available! From the description file, the package provides visualization and analysis tools to aid in the interpretation of neural networks, including functions for plotting, variable importance, and sensitivity analyses. I’ve written at length about each of these functions (see here, here, and here), so I’ll only provide an overview in this post. Most of these functions have remained unchanged since I initially described them, with one important change for the Garson function. Rather than reporting variable importance as -1 to 1 for each variable, I’ve returned to the original method that reports importance as 0 to 1. I was getting inconsistent results after toying around with some additional examples and decided the original method was a safer approach for the package. The modified version can still be installed from my GitHub gist. The development version of the package is also available on GitHub. Please use the development page to report issues.
The package is fairly small but I think the functions that have been included can help immensely in evaluating neural network results. The main functions include:
plotnet
: Plot a neural interpretation diagram for a neural network object, original blog post here# install, load package install.packages(NeuralNetTools) library(NeuralNetTools) # create model AND <- c(rep(0, 7), 1) OR <- c(0, rep(1, 7)) binary_data <- data.frame(expand.grid(c(0, 1), c(0, 1), c(0, 1)), AND, OR) mod <- neuralnet(AND + OR ~ Var1 + Var2 + Var3, binary_data, hidden = c(6, 12, 8), rep = 10, err.fct = 'ce', linear.output = FALSE) # plotnet par(mar = numeric(4), family = 'serif') plotnet(mod, alpha = 0.6)
garson
: Relative importance of input variables in neural networks using Garson’s algorithm, original blog post here# create model library(RSNNS) data(neuraldat) x <- neuraldat[, c('X1', 'X2', 'X3')] y <- neuraldat[, 'Y1'] mod <- mlp(x, y, size = 5) # garson garson(mod, 'Y1')
lekprofile
: Conduct a sensitivity analysis of model responses in a neural network to input variables using Lek’s profile method, original blog post here# create model library(nnet) data(neuraldat) mod <- nnet(Y1 ~ X1 + X2 + X3, data = neuraldat, size = 5) # lekprofile lekprofile(mod)
A few other functions are available that are helpers to the main functions. See the documentation for a full list.
All the functions have S3 methods for most of the neural network classes available in R, making them quite flexible. This includes methods for nnet
models from the nnet package, mlp
models from the RSNNS package, nn
models from the neuralnet package, and train
models from the caret package. The functions also have methods for numeric vectors if the user prefers inputting raw weight vectors for each function, as for neural network models created outside of R.
Huge thanks to Hadley Wickham for his packages that have helped immensely with this process, namely devtools and roxygen2. I also relied extensively on his new web book for package development. Any feedback regarding NeuralNetTools or its further development is appreciated!
Cheers,
Marcus
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.