Describe the issue
I want to exclude early forecast periods from the predicted/forecasted line generated using the SARIMAX model from statsmodels. Tableau reads python code like a table calculation, so the predicted/forecast line must be the same number of data points as the data used to model. The early predictions are unreasonable because there is not have enough data to reasonably forecast.
To Reproduce
Using any monthly timeseries,
SCRIPT_REAL("
from statsmodels.tsa.statespace.sarimax import SARIMAX
Environment information:
Describe the issue I want to exclude early forecast periods from the predicted/forecasted line generated using the SARIMAX model from statsmodels. Tableau reads python code like a table calculation, so the predicted/forecast line must be the same number of data points as the data used to model. The early predictions are unreasonable because there is not have enough data to reasonably forecast.
To Reproduce Using any monthly timeseries,
SCRIPT_REAL("
from statsmodels.tsa.statespace.sarimax import SARIMAX
import pandas as pd
import numpy as np
dates = _arg1
assigned = _arg2
p = min(_arg3)
d = min(_arg4)
q = min(_arg5)
months_forecast = min(_arg6)
P = min(_arg7)
D = min(_arg8)
Q = min(_arg9)
s = min(_arg10)
df = pd.Series(data=assigned,index=dates)
model=SARIMAX(np.log(df), order=(p,d,q),seasonal_order=(P,D,Q,s))
results=model.fit()
pred_uc = results.get_forecast(steps=months_forecast)
pred = results.get_prediction(start=(pd.to_datetime('2013-01-01')) + pd.DateOffset(months=months_forecast), dynamic=False)
data = list(pred.predicted_mean)
data.extend(pred_uc.predicted_mean)
return data
"
,ATTR([Date]),ATTR([Assigned]), MIN([p]), MIN([d]), MIN([q]), min([Forecast Periods]), MIN([P]), MIN([D]), MIN([Q]), MIN([s]))
Expected behavior In python code environment, I can choose how many periods back to predict, but not so in Tableau