Python:在并行模型中运行ARIMA不会发出结果

时间:2019-03-02 19:39:10

标签: python arima

并行运行ARIMA模型未发出结果 大家好,大家好  我已经创建了具有order(0,0,6)的ARIMA模型,并在并行模式下运行它,以便将其推广为order(0,0,367) 这是我的代码:

enter code here
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)

# 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()

# step 5 : Model ARIMA in parallel mode
def arima_Model_Static_PlotErrorAC_PAC(series, arima_order):
    results_MA = modelfitFuncParallel(series)
    return results_MA

        # 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.197]

arima_order = (0, 0, 6)   
outputResidualError = arima_Model_Static_PlotErrorAC_PAC(series, 
arima_order) 

然后,我继续运行模型并等待了很多次(小时),同时没有发出错误,但是我没有收到任何结果(只是空白的运行页面)。 如果有人可以给我任何建议以获得理想的结果,我将不胜感激 问候

0 个答案:

没有答案