1

我对这个系统很陌生,在 python 中也很新。因此,代码中可能很少有多余的行。

我正在尝试使用 x (Hybrid_MF) 预测 y (CARA_Flows)。尽管相同的代码在 Python 中运行良好,但我在画面中遇到错误。错误窗口本身显示了正确的预测(以及未来 12 个月的预测)。

此外,集成没有问题。有人可以帮我理解这里的问题。

SCRIPT_REAL(
"
import pandas as pd
import numpy as np

dateparse = lambda dates: pd.datetime.strptime(dates, '%Y%m')
data = pd.read_excel('S:\AIM India\Anup\Requests_2018\CTI_Forecasting_Tableau\Forecast_CTI_2.xlsx',parse_dates=['YYYYMM'], index_col='YYYYMM',date_parser=dateparse)

ts_exogenMF = data['Hybrid_MF'] 

from statsmodels.tsa.arima_model import ARIMA
model = ARIMA(ts_exogenMF,order=(2, 0, 2))  
results_ARIMA1 = model.fit(disp=-1)  
forecast1,std,conf=results_ARIMA1.forecast(steps=12,alpha=0.5)
forecastMF=forecast1
MF_Arr=[]
MF_Arr=forecastMF

ts = data['CARA_Flows'] 
from statsmodels.tsa.stattools import adfuller
ts_log = np.log(ts)
ts_log_diff = ts_log - ts_log.shift()

model = ARIMA(ts_log,exog=ts_exogenMF,order=(2, 0, 2))  
results_ARIMA2 = model.fit(disp=1)  
Final_Untransformed_Forecast=results_ARIMA2.predict(start=1, end=46, exog=MF_Arr,  dynamic=False)
predictions_ARIMA_log = pd.Series(ts_log.ix[0], index=ts_log.index)
predictions_ARIMA_cumsum = predictions_ARIMA_log.add(Final_Untransformed_Forecast,fill_value=0)
predictions_12M = np.exp(Final_Untransformed_Forecast)

return predictions_12M

",SUM([Hybrid MF]), SUM([CARA Flows]))

在此处输入图像描述

4

2 回答 2

1

该错误是因为日期格式与代码和输出不匹配。所以你应该替换pd.datetime.strptime(x, '%Y-%m-%d')pd.datetime.strptime(dates, '%Y%m')

于 2018-05-10T11:52:19.977 回答
0

当我将输出转换为列表时,这个问题得到了解决。下面是整个代码:

SCRIPT_REAL(
"
import pandas as pd
import numpy as np

dateparse = lambda dates: pd.datetime.strptime(dates, '%Y%m')
data = pd.read_excel('S:\AIM.....\...\ =dateparse)

ts_exogenMF = data['Hybrid_MF'] 

from statsmodels.tsa.arima_model import ARIMA
model = ARIMA(ts_exogenMF,order=(2, 0, 2))  
results_ARIMA1 = model.fit(disp=-1)  
forecast1,std,conf=results_ARIMA1.forecast(steps=12,alpha=0.5)
forecastMF=forecast1
MF_Arr=[]
MF_Arr=forecastMF

ts = data['CARA_Flows'] 
from statsmodels.tsa.stattools import adfuller
ts_log = np.log(ts)
ts_log_diff = ts_log - ts_log.shift()

model = ARIMA(ts_log,exog=ts_exogenMF,order=(2, 0, 2))  
results_ARIMA2 = model.fit(disp=1)  
Final_Untransformed_Forecast=results_ARIMA2.predict(start=0, end=46, exog=MF_Arr,  dynamic=False)
predictions_ARIMA_log = pd.Series(ts_log.ix[0], index=ts_log.index)
predictions_ARIMA_cumsum = predictions_ARIMA_log.add(Final_Untransformed_Forecast,fill_value=0)
predictions_12M = np.exp(Final_Untransformed_Forecast)

predList=pd.Series.tolist(predictions_12M)

return predList

",SUM([Hybrid MF]), SUM([CARA Flows]))
于 2018-05-11T04:34:13.837 回答