TimeSeriesSRC.selpmod

TimeSeriesSRC.selpmod(filename, y, u=[])

Select the best prediction model by grid-searching AIC and BIC.

Exhaustively searches the order combinations defined in a JSON spec file (or dict), fits each candidate model with estimate(), and returns the best models according to both Akaike (AIC) and Bayesian (BIC) criteria.

Parameters:
  • filename (str or dict) – Path to a JSON specification file or a dict with the same structure. The JSON must have a "models" list; each entry is a dict with a "type" key ('arma', 'arx', 'armax', 'bjtf', 'regr') and order keys such as na, nb, nc, nd, nf, diff, delay, per — each holding a list of candidate integer values to try.

  • y (array-like) – Observed output time series.

  • u (array-like, optional) – Input time series (required for ARX, ARMAX, BJTF, regr models). Default [].

Returns:

result – Keyed by model type (e.g. 'arma', 'arx'). Each value is a dict with:

  • 'model' — model type string.

  • 'aic' — list of AIC values for every combination tried.

  • 'bic' — list of BIC values for every combination tried.

  • 'aicstat'stat dict from estimate() for the AIC winner.

  • 'bicstat'stat dict from estimate() for the BIC winner.

  • 'aicmod' — best pmodel selected by AIC.

  • 'bicmod' — best pmodel selected by BIC.

Return type:

dict

Examples

>>> import pathlib, json
>>> import TimeSeriesSRC as ts
>>> spec = {
...     "models": [
...         {"type": "arma", "nc": [1, 2], "nd": [1], "diff": [0], "per": []}
...     ]
... }
>>> data_dir = pathlib.Path(ts.__file__).parent / 'TestData'
>>> import pandas as pd
>>> y = pd.read_csv(data_dir / 'Series_A_Chemical_Concentration.csv').values.flatten()
>>> result = ts.selpmod(spec, y)
>>> best = result['arma']['aicmod']

See also

estimate

Fit a single model.

pmodaic

Akaike Information Criterion.

pmodbic

Bayesian Information Criterion.