I am pretty new to this system and fairly new in python. Thus there might be few redundant lines in the code.
I am trying to forecast y (CARA_Flows) using x (Hybrid_MF). Although the same code is working perfectly fine in Python, I am getting error in tableau. The error window itself shows me the correct forecasting (as well as prediction for the next 12 months).
Also, there's no issue with the integration. Can someone help me understand the issue here.
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]))
This got fixed when I converted the output to a list. Below is the entire code:
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]))