Я выполняю поиск по сетке, чтобы получить оптимальные параметры для моей модели Холт-Винтерса.
Моя проблема не в этом, а в разделении вывода.
# grid search configs
def grid_search(data, cfg_list, n_test, parallel=False):
scores = None
if parallel:
# execute configs in parallel
executor = Parallel(n_jobs=cpu_count(), backend='multiprocessing')
tasks = (delayed(score_model)(data, n_test, cfg) for cfg in cfg_list)
scores = executor(tasks)
else:
scores = [score_model(data, n_test, cfg) for cfg in cfg_list]
# remove empty results
scores = [r for r in scores if r[1] != None]
# sort configs by error, asc
scores.sort(key=lambda tup: tup[1])
return scores
if __name__ == '__main__':
# load dataset
data = series.values
# data split
n_test = 6
# model configs
cfg_list = exp_smoothing_configs(seasonal=[12])
# grid search
scores = grid_search(data, cfg_list, n_test)
print('done')
# list top 3 configs
for cfg, error in scores[:3]:
print(cfg, error)
c=scores[0][0]
print(c)
[None, False, 'add', 12, True, False]
print(type(c))
<class 'str'>
партитуры выглядят так:
print(scores)
[("[None, False, 'add', 12, True, False]", 77287.30870008223), ("[None, False, 'add', 12, True, True]", 82358.18290862873), ("[None, False, 'add', 12, False, False]", 89424.13093850421), ("[None, False, 'add', 12, False, True]", 92702.59197070534), ("[None, False, 'mul', 12, False, False]", 138889.51422419012), ("[None, False, 'mul', 12, False, True]", 143041.76605824768), ("[None, False, 'mul', 12, True, False]", 151094.71387298577), ("[None, False, 'mul', 12, True, True]", 155234.18460656865), ("['add', False, None, 12, True, False]", 286472.4116758029), ("['add', False, None, 12, True, True]", 287519.4400580368), ("['add', True, None, 12, True, False]", 290043.11385268555), ("['add', True, None, 12, True, True]", 291097.96863945096), ("['add', False, None, 12, False, True]", 293015.5612969006), ("['add', False, None, 12, False, False]", 294728.0244142087), ("['mul', False, None, 12, True, True]", 298744.59053811635), ("['add', True, None, 12, False, True]", 298773.6174892717), ("['mul', False, None, 12, False, False]", 299016.44699124835), ("['add', True, None, 12, False, False]", 301282.3881674402), ("['mul', False, None, 12, False, True]", 301539.4816286923), ("['mul', False, None, 12, True, False]", 305131.0375033285), ('[None, False, None, 12, False, False]', 305753.8289179507), ("['mul', True, None, 12, True, True]", 307790.8943120729), ("['mul', True, None, 12, True, False]", 312108.27495445166), ('[None, False, None, 12, True, False]', 313635.56832930725), ('[None, False, None, 12, False, True]', 313762.349260778), ("['mul', True, None, 12, False, True]", 315240.5397127802), ('[None, False, None, 12, True, True]', 315930.0729960225), ("['mul', True, None, 12, False, False]", 319352.33996587264)]
Как я могу распечатать первую запись (которая отсутствует)?Когда я печатаю c [0], вывод будет [.