def test_basic_arima(): arima = ARIMA(order=(0, 0, 0), suppress_warnings=True) preds = arima.fit_predict(y) # fit/predict for coverage # test some of the attrs assert_almost_equal(arima.aic(), 11.201308403566909, decimal=5) assert_almost_equal(arima.aicc(), 11.74676, decimal=5) assert_almost_equal(arima.bic(), 13.639060053303311, decimal=5) # get predictions expected_preds = np.array([ 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876 ]) # generate predictions assert_array_almost_equal(preds, expected_preds) # Make sure we can get confidence intervals expected_intervals = np.array([[-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139]]) _, intervals = arima.predict(n_periods=10, return_conf_int=True, alpha=0.05) assert_array_almost_equal(intervals, expected_intervals)
def test_basic_arma(): arma = ARIMA(order=(0, 0, 0), suppress_warnings=True) preds = arma.fit_predict(y) # fit/predict for coverage # No OOB, so assert none assert arma.oob_preds_ is None # test some of the attrs assert_almost_equal(arma.aic(), 11.201, decimal=3) # equivalent in R # intercept is param 0 intercept = arma.params()[0] assert_almost_equal(intercept, 0.441, decimal=3) # equivalent in R assert_almost_equal(arma.aicc(), 11.74676, decimal=5) assert_almost_equal(arma.bic(), 13.639060053303311, decimal=5) # get predictions expected_preds = np.array([0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876, 0.44079876]) # generate predictions assert_array_almost_equal(preds, expected_preds) # Make sure we can get confidence intervals expected_intervals = np.array([ [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139], [-0.10692387, 0.98852139] ]) _, intervals = arma.predict(n_periods=10, return_conf_int=True, alpha=0.05) assert_array_almost_equal(intervals, expected_intervals)
def run_ARIMA(data, param): order = param['order'] testsize = param['testsize'] T = data.shape[-1] T_test = int((T * testsize) // 1) result_full = np.zeros([data.shape[0], T_test]) total_time = 0 n_round = 0 for i in range(T_test): y = data[..., i:T - T_test + i].copy() n_round += 1 start = time.time() for j in range(y.shape[0]): model = ARIMA(order, suppress_warnings=True, enforce_stationarity=True) result = model.fit_predict(y[j], n_periods=1) result_full[j, i] = result[..., -1] end = time.time() total_time = total_time + (end - start) true_value = data[..., -T_test:] stat = {} stat['acc'] = get_acc(result_full, true_value) stat['nrmse'] = nrmse(result_full, true_value) stat['ave_time'] = total_time / n_round return (stat)