In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Python SARIMAX time series prediction (Python Newbie)

Matthew
11 - Bolide

hey everyone, i am trying to get this script to work, but i'm not very familiar with Python.. can someone please help me figure out how to print the output of this function to alteryx?


ive attached a workflow

NothingButThyme_0-1638383946233.png

 

from ayx import Package
from ayx import Alteryx
from statsmodels.tsa.statespace.sarimax import SARIMAX

df = Alteryx.read("#1")
df

x = df['X']
data = df['Y']

# SARIMA example
# contrived dataset
# fit model
model = SARIMAX(data, order=(1, 1, 1), seasonal_order=(0, 0, 0, 0))
model_fit = model.fit(disp=False)
# make prediction
yhat = model_fit.predict(len(data), len(data))

df['a'] = yhat

Alteryx.write(df, 1)

 

1 REPLY 1
Matthew
11 - Bolide

Got it to work. Part of the problem is that the script wasn't generating new rows to project the prediction into.. I couldn't figure out how to create new rows in python, but I used the Alteryx row generator for that part.

from ayx import Package
from ayx import Alteryx
from statsmodels.tsa.statespace.sarimax import SARIMAX

df = Alteryx.read("#1")
df

x = df['X']
y = df['Y']

# SARIMA example
# contrived dataset
# fit model
model = SARIMAX(y, order=(1, 1, 1), seasonal_order=(3, 1, 3, 12))
model_fit = model.fit(disp=False)
# make prediction
yhat = model_fit.predict(0, len(y)+18)

df['Forecast'] = yhat

Alteryx.write(df, 1)

NothingButThyme_0-1638392990732.png

 

Labels
Top Solution Authors