Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a grid containing all possible parameters for a function?

I have the following parameters:

trend_types = ['add', 'mul']
seasonal_types = ['add', 'mul']
boxcox_options = [True, False, 'log']

To be used in the following function:

model = sm.tsa.ExponentialSmoothing(df, trend=trend_type, seasonal=seasonal_type, use_boxcox=boxcox)
fittedModel = model.fit()

And I would like to generate an array containing all possible combinations, like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
    {trend_type: 'add', seasonal_type: 'add', boxcox: True},
    {trend_type: 'add', seasonal_type: 'add', boxcox: False},
    {trend_type: 'add', seasonal_type: 'add', boxcox: Log},
    {trend_type: 'add', seasonal_type: 'mul', boxcox: True},
    {trend_type: 'add', seasonal_type: 'mul', boxcox: False},
    {trend_type: 'add', seasonal_type: 'mul', boxcox: Log},
    [..]
]

That way I can use such an array like:

for parameter in parameters:
    model = sm.tsa.ExponentialSmoothing(df, trend=parameter.trend_type, seasonal=parameter.seasonal_type, use_boxcox=parameter.boxcox)
    fittedModel = model.fit()

Is there a way to generate such an array?

>Solution :

You can use itertools.product:

from itertools import product

trend_types = ["add", "mul"]
seasonal_types = ["add", "mul"]
boxcox_options = [True, False, "log"]

for t, s, b in product(trend_types, seasonal_types, boxcox_options):
    print(t, s, b)

Prints:

add add True
add add False
add add log
add mul True
add mul False
add mul log
mul add True
mul add False
mul add log
mul mul True
mul mul False
mul mul log
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading