Standalone script example: Generating a Feature Selection model

Starting with a blank canvas, this example builds a stream that generates a Feature Selection model, applies the model, and creates a table that lists the 15 most important fields relative to the specified target.

stream = modeler.script.session().createProcessorStream("featureselection", True)

statisticsimportnode = stream.createAt("statisticsimport", "Statistics File", 150, 97)
statisticsimportnode.setPropertyValue("full_filename", "$CLEO_DEMOS/customer_dbase.sav")

typenode = stream.createAt("type", "Type", 258, 97)
typenode.setKeyedPropertyValue("direction", "response_01", "Target")

featureselectionnode = stream.createAt("featureselection", "Feature Selection", 366, 97)
featureselectionnode.setPropertyValue("top_n", 15)
featureselectionnode.setPropertyValue("max_missing_values", 80.0)
featureselectionnode.setPropertyValue("selection_mode", "TopN")
featureselectionnode.setPropertyValue("important_label", "Check Me Out!")
featureselectionnode.setPropertyValue("criteria", "Likelihood")

stream.link(statisticsimportnode, typenode)
stream.link(typenode, featureselectionnode)
models = []
featureselectionnode.run(models)

# Assumes the stream automatically places model apply nodes in the stream
applynode = stream.findByType("applyfeatureselection", None)
tablenode = stream.createAt("table", "Table", applynode.getXPosition() + 96, applynode.getYPosition())
stream.link(applynode, tablenode)
tablenode.run([])

The script creates a source node to read in the data, uses a Type node to set the role (direction) for the response_01 field to Target, and then creates and executes a Feature Selection node. The script also connects the nodes and positions each on the stream canvas to produce a readable layout. The resulting model nugget is then connected to a Table node, which lists the 15 most important fields as determined by the selection_mode and top_n properties. See the topic featureselectionnode properties for more information.