sampo.api.gen_spd

sampo.api.gen_spd(file=None, template=None, params=None)

Generates SAMPO Process Description from an SPD file, SPD template text file, or template string. Supports multibyte Japanese characters when operating in Python 3.

Parameters
filestring or None

Path of a text file that is SPD syntax compliant.

templatestring or None

String object that is SPD template syntax compliant. Templates follow Jinja2 syntax. http://jinja.pocoo.org/docs/2.10/ If file is specified, this parameter is ignored.

paramsdict or None

Parameters to render on to templates. Newlines in string parameters are converted to spaces. If SPD base syntax is followed by file or template this parameter is ignored.

Returns
spdsampo.core.ProcessDescription

Examples

>>> from sampo.api import gen_spd
>>> spd = gen_spd(file=fabhmerg.spd)
>>> from sampo.api import gen_spd
>>> spd_content = '''
... dl -> std  -> rg
...
... ---
...
... components:
...     dl:
...         component: DataLoader
...
...     std:
...         component: StandardizeFDComponent
...         features: scale == 'real' or scale == 'integer'
...
...     rg:
...         component: FABHMEBernGateLinearRgComponent
...         features: name != 'price'
...         target: name == 'price'
...         standardize_target: True
...         tree_depth: 3
...
... global_settings:
...     keep_attributes:
...         - price
...     feature_exclude:
...         - price
... '''
>>> spd = gen_spd(template=spd_content)
>>> from sklearn.model_selection import ParameterGrid
>>> from sampo.api import gen_spd
>>> spd_templ = '''
... dl -> std -> rg
...
... ---
...
... components:
...    dl:
...        component: DataLoader
...
...    std:
...        component: StandardizeFDComponent
...        features: scale == 'real' or scale == 'integer'
...
...    rg:
...        component: FABHMEBernGateLinearRgComponent
...        features: name != 'price'
...        target: name == 'price'
...        standardize_target: {{ standardize_target }}
...        tree_depth: {{ tree_depth }}
...
... global_settings:
...    keep_attributes:
...        - num_sales
...
...    feature_exclude:
...        - num_sales
... '''
>>> spd_grid = {}
>>> spd_param_combination = {
...     "standardize_target": [True, False],
...     "tree_depth": [3, 5]
... }
>>> spd_params = list(ParameterGrid(spd_param_combination))
>>> for grid_id, spd_param in enumerate(spd_params):
...     spd_grid[grid_id] = gen_spd(template=spd_templ, params=spd_param)