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 asna,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'—statdict fromestimate()for the AIC winner.'bicstat'—statdict fromestimate()for the BIC winner.'aicmod'— bestpmodelselected by AIC.'bicmod'— bestpmodelselected by BIC.
- Return type:
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']