複数のストリームの処理: スタンドアロン スクリプト

複数のストリームを処理するには、 スタンドアロン スクリプトを使用する必要があります。スタンドアロン スクリプトは、IBM® SPSS® Modeler UI 内で編集して実行するか、 バッチ・モードでコマンド・ライン・パラメーターとして渡すことができます。

以下のスタンドアロン スクリプトは 2 つのストリームを開きます。一方のストリームはモデルを作成し、2 番目のストリームは予測値の分布をプロットします。

# Change to the appropriate location for your system
demosDir = "C:/Program Files/IBM/SPSS/Modeler/18.3.0/DEMOS/streams/"

session = modeler.script.session()
tasks = session.getTaskRunner()

# Open the model build stream, locate the C5.0 node and run it
buildstream = tasks.openStreamFromFile(demosDir + "druglearn.str", True)
c50node = buildstream.findByType("c50", None)
results = []
c50node.run(results)

# Now open the plot stream, find the Na_to_K derive and the histogram
plotstream = tasks.openStreamFromFile(demosDir + "drugplot.str", True)
derivenode = plotstream.findByType("derive", None)
histogramnode = plotstream.findByType("histogram", None)

# Create a model applier node, insert it between the derive and histogram nodes
# then run the histgram
applyc50 = plotstream.createModelApplier(results[0], results[0].getName())
applyc50.setPositionBetween(derivenode, histogramnode)
plotstream.linkBetween(applyc50, derivenode, histogramnode)
histogramnode.setPropertyValue("color_field", "$C-Drug")
histogramnode.run([])

# Finally, tidy up the streams
buildstream.close()
plotstream.close()
さらに次の例は、開いているストリーム (「ストリーム」タブで開いているすべてのストリーム) を反復処理する方法を示しています。これは、スタンドアロン スクリプトでのみサポートされることに注意してください。
for stream in modeler.script.streams():
    print stream.getName()