Reputation: 5962
What is the correct way to predict p, d and q value for parameters for ARIMA model.
How Grid Search help to find these parameters?
How to make Non stationary data to stationary to apply ARIMA?
I have already referred this article
Upvotes: 2
Views: 4989
Reputation: 71
For grid Searching Method you can use an approach which is broken down into two parts:
this the code:
# evaluate an ARIMA model for a given order (p,d,q)
def evaluate_arima_model(X, arima_order):
# prepare training dataset
train_size = int(len(X) * 0.66)
train, test = X[0:train_size], X[train_size:]
history = [x for x in train]
# make predictions
predictions = list()
for t in range(len(test)):
model = ARIMA(history, order=arima_order)
model_fit = model.fit(disp=0)
yhat = model_fit.forecast()[0]
predictions.append(yhat)
history.append(test[t])
# calculate out of sample error
error = mean_squared_error(test, predictions)
return error
# evaluate combinations of p, d and q values for an ARIMA model
def evaluate_models(dataset, p_values, d_values, q_values):
dataset = dataset.astype('float32')
best_score, best_cfg = float("inf"), None
for p in p_values:
for d in d_values:
for q in q_values:
order = (p,d,q)
try:
mse = evaluate_arima_model(dataset, order)
if mse < best_score:
best_score, best_cfg = mse, order
print('ARIMA%s MSE=%.3f' % (order,mse))
except:
continue
print('Best ARIMA%s MSE=%.3f' % (best_cfg, best_score))
For more details you can find in this link a tutorial, in which grid search ARIMA hyperparameters for a one-step rolling forecast is developped, https://machinelearningmastery.com/grid-search-arima-hyperparameters-with-python/
Upvotes: 7