The terminate hook is a good place to do any post-model analysis, as the data will be finalized by that point. This example runs an OLS regression on two columns of model data.
@heli.hook
def terminate(model, data):
import statsmodels.api as sm
reg = sm.OLS(data['M0'], data['price-level']).fit()
predictions = reg.predict(data['M0'])
# Print out the statistics
reg.summary()
If you launch another Matplotlib window in post-analysis, you must make sure not to block the event loop; otherwise you cannot launch a new model until the window is closed. This can be done with the block=False argument on pyplot.show().
This example shows an impulse response function after each model run, without blocking further runs.
@heli.hook
def terminate(model, data):
from statsmodels.tsa.api import VAR
import matplotlib.pyplot as plt
model = VAR(data)
results = model.fit(50)
irf = results.irf(50)
irf.plot(orth=False, impulse='M0', response='ratio-jam-axe')
plt.show(block=False)
Contribute a Note
History
⚠️ 1.0Takes the model object rather than the GUI object as the first argument.
charwick
Mar 26, 2020 at 18:12The
terminate
hook is a good place to do any post-model analysis, as the data will be finalized by that point. This example runs an OLS regression on two columns of model data.charwick
Jul 12, 2022 at 18:53If you launch another Matplotlib window in post-analysis, you must make sure not to block the event loop; otherwise you cannot launch a new model until the window is closed. This can be done with the
block=False
argument onpyplot.show()
.This example shows an impulse response function after each model run, without blocking further runs.