Reference 〉 Hook

terminate(modelHelipad, datapandas.DataFrame)

Runs when a model terminates.

Required Parameters

  • model Helipad

    The model object.

  • data pandas.DataFrame

    The final model data.

Notes and Examples

  1. charwick

    Mar 26, 2020 at 18:12

    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()
  2. charwick

    Jul 12, 2022 at 18:53

    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)
  3. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History