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:
[
{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