Stream script example: Training a neural net

A stream can be used to train a neural network model when executed. Normally, to test the model, you might run the modeling node to add the model to the stream, make the appropriate connections, and execute an Analysis node.

Using an IBM® SPSS® Modeler script, you can automate the process of testing the model nugget after you have created it. For example, the following stream script to test the demo stream druglearn.str (available in the /Demos/streams/ folder under your IBM SPSS Modeler installation) could be run from the Stream Properties dialog (Tools > Stream Properties > Script):

stream = modeler.script.stream()
neuralnetnode = stream.findByType("neuralnetwork", None)
results = []
neuralnetnode.run(results)
appliernode = stream.createModelApplierAt(results[0], "Drug", 594, 187)
analysisnode = stream.createAt("analysis", "Drug", 688, 187)
typenode = stream.findByType("type", None)
stream.linkBetween(appliernode, typenode, analysisnode)
analysisnode.run([])

The following bullets describe each line in this script example.

  • The first line defines a variable that points to the current stream.
  • In line 2, the script finds the Neural Net builder node.
  • In line 3, the script creates a list where the execution results can be stored.
  • In line 4, the Neural Net model nugget is created. This is stored in the list defined on line 3.
  • In line 5, a model apply node is created for the model nugget and placed on the stream canvas.
  • In line 6, an analysis node called Drug is created.
  • In line 7, the script finds the Type node.
  • In line 8, the script connects the model apply node created in line 5 between the Type node and the Analysis node.
  • Finally, the Analysis node is executed to produce the Analysis report.

It is possible to use a script to build and run a stream from scratch, starting with a blank canvas.