Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

How to Create a Plot of an Alteryx Neural Network Model

SydneyF
Alteryx Alumni (Retired)
Created

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 calledNeuralNetToolswhich creates a whole bunch of handy plots of a trained neural network model. It works on a few different R packages, includingnnet(the package Alteryx uses). The author and maintainer of the NeuralNetTools package, Marcus W. Beck, also has a blog calledR 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.

 

trainNeuralNetwork.png

 

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.

 

addRtool.png

 

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 anAlteryx Analytic Application,through a command prompt, or with a customconditional 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 Networkvisualization.

 

First, you will need to load both thennetand NeuralNetTools packages.

 

#load needed R packages library(nnet) library(NeuralNetTools)

Next, you will need to read in the Neural Network Model object (the outputin 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  

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 theplotnet() 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 plotnet(mod.obj) 

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

 

addbrowse.png

 

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!

 

neuralnetoutput.png

 

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

 

Comments
shaynie
8 - Asteroid

Hi Sydney,

This is exactly what I'd like to do, but my R coding skills are nonexistent.  Would you mind sharing the workflow with the R tool?
Thank you!

VictorCruz
Alteryx
Alteryx

Hello Alteryx Users,

many must be wondering how to read the model object using the R language and then successfully be able to plot the neural network graph using R's package.

Below is an example for you to succeed in this task:

 

 

library(nnet)
library(NeuralNetTools)



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



# Make sure that it is in fact 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")



# The model object has been serialized as a string,
# which on being read from Alteryx is converted to an R factor.
# The line of code first coerces the serialized model string to
# a string (in R a "character" data type) and the unserialized the model object
mod.obj <- unserializeObject(as.character(the.model$Object[1]))




AlteryxGraph(1, width=576, height=576)
#Insira o código para plotar o gráfico aqui
#plot the neural network
plotnet(mod.obj)



invisible(dev.off())

 

 

It is worth remembering that the generated graph is in its simplest form, you can customize it to be more complete using R language.

Hope this helps.

Regards,

shaynie
8 - Asteroid

Thanks so much, Victor!  Worked beautifully after I installed the NeuralNet Tools.