Interpret the results of a model
items = dummy_data_generator(50, 10, nrows=100)
dbunch = TSDataLoaders.from_items(items, horizon = 5, lookback = 20, step=5)
dbunch.show_batch(max_n=6)
learn = nbeats_learner(dbunch, layers=[100])
learn.lr_find()
learn.fit_flat_cos(3, 2e-1)
learn.recorder.plot_loss()
learn.show_results(max_n=9)
learn.metrics = []
dct = {'foo':{'bar':1},'bar':2,'foo2':{'foo3':3},'ignore':{'bar':1000}}
r = _get_key_from_nested_dct(dct,'bar',['ignore'])
test_eq(r,{'foobar': 1, 'bar': 2})
from fastai2.interpret import *
interp = NBeatsInterpretation.from_learner(learn)
dct = {'bias0_0_f':torch.ones(1,1), 'bias0_1_f': torch.ones(1,1), 'bias0_2_f': torch.ones(1,1),'bias0_1_b': torch.ones(1,1)*10,
'trend1_0_f': torch.ones(1,1)*100, 'trend1_1_f':torch.ones(1,1)*100}
res = add_stack(dct)
test_eq(res,{'trend1_f': tensor([[200.]]), 'bias0_f': tensor([[3.]]), 'bias0_b': tensor([[10.]])})
dct = {'bias0_0_full':torch.ones(1,1), 'bias0_1_full': torch.ones(1,1), 'bias0_2_full': torch.ones(1,1),
'trend1_1_full':torch.ones(1,1)*100,'trend1_2_full':torch.ones(1,1)*100}
res = add_stack_full(dct)
test_eq(res,{'trend1_full':torch.ones(1,1)*200,'bias0_full': tensor([[3.]])})
interp.plot_top_losses(3, combine_stack= True)
TODO: make the scale work TODO2: something seems of besides the scale the last part seems not to be shown