python 15 lines · 1 tab

Time series forecasting with statsmodels SARIMAX baselines

1 tab
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX

df = pd.read_csv('daily_revenue.csv', parse_dates=['date']).set_index('date')

model = SARIMAX(
    df['revenue'],
    order=(1, 1, 1),
    seasonal_order=(1, 1, 1, 7),
    enforce_stationarity=False,
    enforce_invertibility=False,
)
result = model.fit(disp=False)
forecast = result.get_forecast(steps=14)
print(forecast.predicted_mean)
1 file · python Explain with highlit

For many business forecasting tasks, a carefully tuned statistical baseline is still the right first step. SARIMAX makes seasonality, trend, and external regressors explicit, which is useful when stakeholders want understandable drivers. I use it before escalating to more opaque sequence models.

Share this code

Here's the card — post it anywhere.

Time series forecasting with statsmodels SARIMAX baselines — share card
Link copied