Tuesday 5 January 2021

Optimize ARIMA walk-forward validation

Just fitted and ARIMA model

model = ARIMA(Preco1, order=(6,1,2))
model_fit = model.fit(disp=0)

In order to do the walk-forward validation of an ARIMA model on a data with 8760 samples, I have split the df into train and test sets

X = df.values
size = int(len(X) * 0.80)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()

and then was using the following

for t in range(len(test)):
    model = ARIMA(history, order=(6,1,2)) # Change with results from above
    model_fit = model.fit(disp=0)
    output = model_fit.forecast()
    yhat = output[0]
    predictions.append(yhat)
    obs = test[t]
    history.append(obs)
    print('predicted=%f, expected=%f'% (yhat, obs))

timeseries_evaluation_metrics_func(test, predictions)

As with the for loops takes huge amounts of time to run, even on 4 vCPUs, how should I do the walk-forward validation and still get the desired metrics for evaluation?

I have tried a list comprehension but it doesn't make it better

def wfvalidation(t):
    model = ARIMA(history, order=(6,1,2)) # Change when needed
    model_fit = model.fit(disp=0)
    output = model_fit.forecast()
    yhat = output[0]
    predictions.append(yhat)
    obs = test[t]
    history.append(obs)
    print('predicted=%f, expected=%f'% (yhat, obs))
    
predictions = [wfvalidation(t) for t in range(len(test))]


from Optimize ARIMA walk-forward validation

No comments:

Post a Comment