我是Python的新用户。我开发了一个模型,它使用auto\u arima来预测超过11000个时间序列,这些时间序列的日值是过去1000天的。我拥有数据帧df_ts
中的所有时间序列,并使用以下代码循环遍历所有时间序列,并将预测结果存储在数据帧fcast
。你知道吗
fcast_period = 60
col_len = len(df_ts.columns)
fcast = pd.DataFrame({'MonthDEV':pd.date_range(start = today,
periods = fcast_period).tolist()})
def arm(column):
for column in df_ts:
stepwise_fit = pm.auto_arima(df_ts[column], start_p=1, start_q=1,
max_p=3, max_q=3, m=7,
start_P=0, seasonal=True,
d=1, D=1, trace=True,
error_action='ignore',
suppress_warnings=True,
stepwise_fitwise=True)
stepwise_fit.fit(df_ts[column])
forecast = pd.DataFrame()
x = 0
if x < col_len:
fc = stepwise_fit.predict(n_periods = fcast_period)
forecast = pd.DataFrame({'MonthDEV':pd.date_range(start = today,
periods = fcast_period).tolist(),
df_ts.columns.values[x]: fc})
global fcast
fcast = pd.merge(fcast, forecast, on = 'MonthDEV', how = 'outer')
x = x + 1
arm(column)
当我试图运行这段代码时,执行它需要100多个小时(AWS实例有18核CPU和256GB内存)。我理解它是因为python使用单核是因为GIL。我试图使用多处理,但无法正确设置。你知道吗
if __name__ == '__main__':
p = multiprocessing.Pool()
arima_forecast = p.map(arm, col_len)
p.close()
print(arima_forecast)
是否可以使用多处理池执行此代码,以强制它在2-3小时内执行?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐