def train_model_autoarima(y, x, output: bool = True) -> AutoARIMA: if output: logger.info("Training AutoARIMA model...") timer = Timer() model = AutoARIMA(suppress_warnings=True, error_action='ignore') y = pd.Series(data=np.delete(y, 0)) x = pd.DataFrame(data=x[:-1]) model.fit(y, x) if output: model.summary() logger.info(f'Done in {timer}') return model
plt.style.use('ggplot') df = pd.read_csv( 'https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'], index_col="date") df.index = pd.PeriodIndex(df.index, freq="M") series = df.T.iloc[0] plot_series(series) model_auto = AutoARIMA(sp=12, suppress_warnings=True).fit(series) summary = model_auto.summary() def get_params(summary_text): full = re.findall(r'SARIMAX\(.*?\)x\(.*?\)', summary_text)[0] info = [int(_) for _ in re.findall(r'\d+', full)] return info p, d, q, P, D, Q, S = get_params(summary.as_text()) y_train, y_test = temporal_train_test_split(series, test_size=24) fh = ForecastingHorizon(y_test.index, is_relative=False) plot_series(y_train, y_test, labels=['Train', 'Test'])