Mar-02-2019, 07:20 PM
(This post was last modified: Mar-02-2019, 07:20 PM by wissam1974.)
Hi All experts,
I have created ARIMA model with order(0,0,6) and run it in a parallel mode in order to generalize it to an order(0,0,367)
Here is my code:
If someone can give me any suggestion to get the desired result I will be grateful
Regards
I have created ARIMA model with order(0,0,6) and run it in a parallel mode in order to generalize it to an order(0,0,367)
Here is my code:
from matplotlib import pyplot from statsmodels.tsa.arima_model import ARIMA from sklearn.metrics import mean_squared_error from statsmodels.graphics.tsaplots import plot_acf from statsmodels.graphics.tsaplots import plot_pacf from math import sqrt import os import multiprocessing as mp # step1 Order List Sections: Divide order into 3 sections each of which is a list of lenght 2 def divideOrderInList(): pqOrderList = list() x = list() for i in range(1, 2 + 1): # 1->2 x.append(i) y = list() for i in range(2 + 1, 4 + 1): # 3->4 y.append(i) z = list() for i in range(4 + 1, 6 + 1): # 5->6 z.append(i) pqOrderList = (x, y, z) print(pqOrderList) return (pqOrderList) # step 2 : Create the 'modelfitFunc' function : this is the construction model function def modelfitFunc(series, sectionOrder): expctd=series q1 = 0 q2 = len(sectionOrder) - 1 for q in (sectionOrder[q1], sectionOrder[q2]): arima_order = (0, 0, q) model = ARIMA(series, order=arima_order) results_MA = model.fit(disp=-1, start_params=[.1 for i in range(1 + arima_order[2])]) yhatList = results_MA.fittedvalues residuals = [expctd[i] - yhatList[i] for i in range(len(expctd))] pyplot.figure() pyplot.subplot(211) # 211 plot_acf(residuals, ax=pyplot.gca(), lags=10) pyplot.subplot(212) # 212 plot_pacf(residuals, ax=pyplot.gca(), lags=10) pyplot.show() mse = mean_squared_error(expctd, yhatList) rmse = sqrt(mse) print(results_MA.summary()) print(rmse) #return residuals # step 3 : Define 'funcThread' thread function def modelfitFuncThread(series, listOrder): for sectionOrder in listOrder: modelfitFunc(series, sectionOrder) # step 4 : Define funcParallel : modelfitFuncParallel def modelfitFuncParallel(series): if __name__ == "__main__": listOrder = divideOrderInList() #Result ([1, 2], [3, 4], [5, 6]) nCPU = os.cpu_count() # print(nCPU) =8 exit() pool = mp.Pool(nCPU) results_MA = pool.apply(modelfitFuncThread, args=(series, listOrder)) pool.close() pool.join() return results_MA # step 5 : Model ARIMA in parallel mode def arima_Model_Static_PlotErrorAC_PAC(series, arima_order): results_MA = modelfitFuncParallel(series) # step 6 : Call and Running Model ARIMA in parallel mode series=[3.9, -1.4, 2.0, 3.4, 4.9, 1.792, 2.299, 0.6999, 1.5, 0.0, 1.19999, 5.4, 5.79, 3.5, 3.29, 3.0, 3.71, 3.1, -1.69993, -1.9004, -1.2001, 2.1, 3.201, -0.5, -2.8007, -4.9, -4.30002, -5.1, -1.0, 1.7008, 0.5, 2.1, 1.0996, 2.896, 1.94, 1.307, -0.94, 2.58, -1.84, 0.693, -4.08, -2.0, -0.799972, 0.599996, -1.9984, -0.386, -2.0, -3.396, -3.386, -2.0, -4.899, -4.402, 1.0, -0.39986, 0.30007, 1.19999993, 2.1999999999999997] arima_order = (0, 0, 6) outputResidualError = arima_Model_Static_PlotErrorAC_PAC(series, arima_order)After then, I have proceeded to run my model and waited for larges times(hours) no error is issuing at meanwhile but I did not receive any result (just blank running page)
If someone can give me any suggestion to get the desired result I will be grateful
Regards