Showing results for 
Search instead for 
Did you mean: 

Alteryx Designer Knowledge Base

Definitive answers from Designer experts.

How to Create a Plot of an Alteryx Neural Network Model

Sr. Data Science Content Engineer
Sr. Data Science Content Engineer
Created on

Neural Networks are frequently referred to as "black box" predictive models. This is because the actual inner workings of why a Neural Network sorts data the way it does are not explicitly available for interpretation. A wide variety of work has been conducted to make Neural Networks more transparent, ranging from visualization methods to developing a Neural Network model that can “show it’s work”.


If you’re using the Neural Network Tool in Alteryx, you have different plots that demonstrate the efficacy of the model included in the Report (R) output Anchor. These plots are very helpful for interpretation but don’t provide a schematic for how the network looks.


There is an R package on CRAN called NeuralNetTools which creates a whole bunch of handy plots of a trained neural network model. It works on a few different R packages, including nnet (the package Alteryx uses). The author and maintainer of the NeuralNetTools package, Marcus W. Beck, also has a blog called R is my friend, where he discusses the plotting functions included in his package (along with other cool neural network stuff, and general fun in R).


You can use this package to create visualizations of your Alteryx-created Neural Networks by bringing the model object created by the Neural Network tool into the mighty R tool. The steps to do so are as follows:


1. Train a Neural Network model with the Neural Network tool.




2. Once the model is trained, add an R tool on to the canvas, and connect the O anchor to the R tool’s input.




Now we can start coding! Because the NeuralNetTools package is not installed with the Alteryx Predictive Tools by default, you will need to install the package yourself. You can do this a few different ways, including an Alteryx Analytic Application, through a command prompt, or with a custom conditional install function in the R tool. No matter how you do it, once this package is installed and available for use in your R installation connected to Alteryx, you only need a few lines of code in your R tool to create a Neural Network visualization. 


First, you will need to load both the nnet and NeuralNetTools packages. 


#load needed R packages

Next, you will need to read in the Neural Network Model object (the output in the O anchor of the Neural Network tool) into the R tool, confirm that it is a model object, and unserialize the model object.


#read in the Alteryx stream containing the model object
the.model <- read.Alteryx("#1")

#check that the input is a model object, and return an error if it is not
if (!all(names(the.model) %in% c("Name", "Object")))
    stop.Alteryx("A model object was not provided")

#unserialize model object
mod.obj <- unserializeObject(as.character(the.model$Object[1]))

The last step is to create a plot in the first output anchor of the R tool, and populate it with a plot of the neural network with the plotnet() function from the NeuralNetTools package.


#create a slot for an output graph in anchor 1
AlteryxGraph(1, width=576, height=576)

#plot the neural network

3. Now you can add a couple of Browse tools, and run your workflow!




The plot generated by the R tool returned in the first output anchor will be a diagram of the neural network you trained with the Neural Network tool! 




You can apply this same process to create additional visualizations of any of the Predictive Tool models with an appropriate R package.