How to pass arguments to a Python script in SPSS Modeler Batch

How to pass arguments to a Python script in SPSS Modeler Batch

What is SPSS Modeler Batch?

CaDS is a good choice for regular processing of streams created with SPSS Modeler, but if you don't need that much fine-grained management or the scale isn't large, SPSS Modeler Batch is also a good choice. I will. SPSS Modeler Batch connects to SPSS Modeler Server and executes streams by executing from a command. GUIs like SPSS Modeler Client will not launch. Basically it runs all the terminal nodes placed in the stream. SQL pushback and cache set in the stream also work effectively. As an example of how to use it, if there is a process such as executing sales forecast of a certain business every day or updating the forecast model every week, create a stream to perform that process and batch command (clemb) of SPSS Modeler Batch. Can be achieved by executing at the specified time from another scheduler (CRON etc. for UNIX).

Command example


clemb -stream "/XXX/.../XXX.str" -execute -server -hostname XXX -username XXX -password XXX -Pmth=Jan

You can pass arguments to the stream with the -P option when running SPSS Modeler Batch. As described in the following manual, for example, if you write Month ='\ $ P-mth' in the condition extraction node and execute it with the argument -Pmth = Jan when executing in the modeler batch, mth = Jan is carried over to the stream. Month ='\ $ P-mth' becomes Month ='Jan', which allows you to extract only the data that corresponds to Month ='Jan'. It is also possible to extract data under different conditions such as Month ='Feb' by changing the character string following -Pmth = in batch execution.

"Use parameters in batch mode" (In the manual, the equation is ==, but it is equivalent to =.)

If you use this method and execute it by giving a branch name as an argument to one stream, you can also forecast sales and update the model for each branch.

Incorporating arguments into a Python script

As mentioned above, SPSS Modeler Batch will execute all terminal nodes in the specified stream, but if you want to execute only a specific terminal node, specify the order in which the terminal nodes are executed, or update the model. , Controlled by the accompanying Python script. The method shown in the manual link above was to incorporate the arguments into the CLEM expression set inside the node of the stream, but I would also like to introduce how to incorporate the arguments into the Python script that accompanies the stream. For example, if you want to pass the branch name with the option Branch, set it with -PBranch = as shown below.

Command entry example


clemb -stream ...(Omission)... -PBranch=GINZA

To include it in a Python script, use the getParameterValue () method of the session () or stream () instance. There is a difference that stream () is valid for the target stream and session () is valid for all open streams, but the parameters obtained by Modeler Batch are obtained from both session () and stream (). I can do it. For session () and stream (), write them in the Python script as shown in the following example.

session()in the case of


session = modeler.script.session()
Branch_Name = session.getParameters().getParameterValue('Branch')

stream()in the case of


stream = modeler.script.stream()
Branch_Name = stream.getParameterValue('Branch')

If you execute the batch with this, ‘GINZA’ will be assigned to the Branch_Name variable in the previous example. After that, you can handle it freely, such as assigning it to the CLEM expression of the node in the Python script. Variables are imported as character strings, so if you want to treat them as numbers, you need to perform type conversion such as int ().

There is also a description in the following manual about importing parameters into Python scripts. (It's a little confusing.)

"Streams, sessions, and supernode parameters"

Recommended Posts

How to pass arguments to a Python script in SPSS Modeler Batch
How to get a stacktrace in python
[Python / Tkinter] How to pass arguments to command
How to run a Maya Python script
How to receive command line arguments in Python
How to clear tuples in a list (Python)
How to embed a variable in a python string
Let's understand how to pass arguments (Python version)
How to create a JSON file in Python
How to notify a Discord channel in Python
[Python] How to draw a histogram in Matplotlib
How to pass the execution result of a shell command in a list in Python
How to convert / restore a string with [] in python
[Python] How to expand variables in a character string
A memorandum to run a python script in a bat file
How to manage arguments when implementing a Python script as a command line tool
Execute Python function from Powershell (how to pass arguments)
How to develop in Python
How to execute a command using subprocess in Python
How to pass arguments when invoking python script from blender on the command line
How to slice a block multiple array from a multiple array in Python
How to run a Python program from within a shell script
A story about how to specify a relative path in python.
How to use the __call__ method in a Python class
How to launch AWS Batch from a python client app
How to import a file anywhere you like in Python
How to define multiple variables in a python for statement
I tried "How to get a method decorated in Python"
How to develop in a virtual environment of Python [Memo]
How to get the last (last) value in a list in Python
How to get a list of built-in exceptions in python
How to write a Python class
[Python] How to do PCA in Python
How to collect images in Python
How to use SQLite in Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
Pass arguments to Task in discord.py
How to handle Japanese in Python
Write a batch script with Python3.5 ~
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to batch start a python program created with Jupyter notebook
How to determine the existence of a selenium element in Python
How to make a string into an array or an array into a string in Python
[Introduction to Python] How to output a character string in a Print statement
How to check the memory size of a variable in Python
How to get a string from a command line argument in python
How to create a heatmap with an arbitrary domain in Python
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
I wrote a function to load a Git extension script in Python
[For beginners] How to register a library created in Python in PyPI
I wrote a script to extract a web page link in Python
How to delete multiple specified positions (indexes) in a Python list
How to determine if a shell script was started in bash
How to access environment variables in Python
How to dynamically define variables in Python
[Python] How to make a class iterable
How to do R chartr () in Python