pyhctsa.operations.model_fit.compare_test_sets

pyhctsa.operations.model_fit.compare_test_sets(y, the_model='ss', ord=2, subset_how='rand', sample_p=(20, 0.1), steps=2, random_seed=0)

How well a model fitted to the whole series predicts short stretches of it.

Fits a time-series model to the full series, then uses it to predict a set of short test segments of the series (steps samples ahead), and summarizes how the prediction quality varies across the segments. For each segment it records the root-mean-square prediction error, the lag-1 autocorrelation of the errors, the absolute difference between the mean prediction and the mean of the data, and the ratio of the standard deviations of the predictions and the data. It says something about stationarity in the spread of values, and about the suitability of the model in the level of values.

Similar to fit_subsegments(), except that the model is fitted on the full time series and tested on different local segments. The predictions of the fitted model start from a diffuse initial state at the start of each segment (_prediction_errors()); the first samples of a segment, which determine it, are not predicted.

Parameters:
y : array-like

The input time series.

the_model : {'ss', 'ar', 'arma'}, optional

The type of time-series model to fit: a state-space model ('ss'), an AR model ('ar') or an ARMA model ('arma'). Default is 'ss'.

ord : int, 'best' or two-vector, optional

The order of the model to fit (a two-element vector for 'arma'), or 'best' to select it automatically: for 'ar', the order from 1 to 10 minimizing the Schwarz Bayesian criterion (ARFIT); for 'ss', the order minimizing Akaike’s information criterion. Default is 2.

subset_how : {'rand', 'spread', 'uniform'}, optional

How to select the test segments: at random, with start points from the golden-ratio sequence frac(j*phi) (deterministic and evenly spread), or evenly spaced throughout the time series. Default is 'rand'.

sample_p : two-vector, optional

[number of segments, segment length]. A segment length below 1 is a fraction of the series length, capped to between 10 and 20 samples (so [25, 0.1] takes 25 segments of 10 to 20 samples); otherwise it is a number of samples. A single value (with 'uniform') partitions the series into that many segments. Default is [20, 0.1].

steps : int, optional

The number of steps ahead to predict in each segment. Default is 2.

random_seed : int, 'default', 'none' or None, optional

The seed of the random segment starts, as hctsa’s BF_RandomSeed: a number, 'default' or None for seed 0, or 'none' for a seed drawn from NumPy’s global state. The draws come from the portable generator (pyhctsa.robust.bf_random()), so they are hctsa’s. Default is 0.

Returns:

  • stde_mean, stde_std, stde_iqr: the mean, standard deviation and interquartile range over segments of the root-mean-square prediction error,

  • ac1_mean, ac1_median: the absolute value of the mean, and of the median, over segments of the lag-1 autocorrelation of the prediction errors,

  • ac1_std, ac1_iqr: the standard deviation and interquartile range over segments of that autocorrelation (segments whose prediction errors do not vary beyond the level of rounding, _is_rounding_level(), are excluded from the four ac1 statistics),

  • meane_mean, meane_std, meane_iqr: the mean, standard deviation and interquartile range over segments of the absolute difference between the mean prediction and the mean of the data,

  • stdrat_mean, stdrat_median, stdrat_std, stdrat_iqr: the mean, median, standard deviation and interquartile range over segments of the ratio of the standard deviation of the predictions to that of the data (segments in which the data are near-constant are excluded).

NaN if the model cannot be fitted.

Return type:

dict