def _fit_arima(x, xreg, order, seasonal_order, start_params, trend,
method, transparams, solver, maxiter, disp, callback,
fit_params, suppress_warnings, trace, error_action,
out_of_sample_size, scoring, scoring_args):
start = time.time()
try:
fit = ARIMA(order=order, seasonal_order=seasonal_order,
start_params=start_params, trend=trend, method=method,
transparams=transparams, solver=solver, maxiter=maxiter,
disp=disp, callback=callback,
suppress_warnings=suppress_warnings,
out_of_sample_size=out_of_sample_size, scoring=scoring,
scoring_args=scoring_args)\
.fit(x, exogenous=xreg, **fit_params)
# for non-stationarity errors or singular matrices, return None
except (LinAlgError, ValueError) as v:
if error_action == 'warn':
warnings.warn(_fmt_warning_str(order, seasonal_order))
elif error_action == 'raise':
# todo: can we do something more informative in case
# the error is not on the pyramid side?
raise v
# if it's 'ignore' or 'warn', we just return None
fit = None
# do trace
if trace:
print('Fit ARIMA: %s; AIC=%.3f, BIC=%.3f, Fit time=%.3f seconds'
% (_fmt_order_info(order, seasonal_order),
fit.aic() if fit is not None else np.nan,
fit.bic() if fit is not None else np.nan,
time.time() - start if fit is not None else np.nan))
return fit
评论列表
文章目录