# Python uses ARIMA and arimax to predict the time series data of store commodity sales demand

2022-06-24 08:56:23

## The source of the original text is ： The official account of the tribal public

This paper explores different time series techniques on relatively simple data sets .

Given 5 Store sales data for , And ask you to predict 10 From different stores 50 Different products in 3 Sales within months .

What is the best way to deal with seasonality ？ The store should be modeled separately , They can still be combined ？

# Store project demand forecast

## Autoregressive composite moving average (ARIMA)

this  ARIMA  The model can be applied to nonstationary time series ARMA Generalization of the model .

``````import time
import pandas as pd

%matplotlib inline
``````

``````d_trn = pd.rad_csv('../inuraicsv, prse_tes=date'], inx_col['te'])
d_ts = pd.ra_csv'../iputst.csv', prse_des=['date'], ine_col['d``````   All stores seem to show the same trend and seasonality .

## ARIMAX

Autoregressive composite moving average with explanatory variables (ARIMAX) yes ARIMA Extended version of , These include independent predictors .

# Prepare the data

``````mnths = df_rinindx.nth

df_ran.drpna(iplac=True) ``````import datetime

dumymns = pd.get_dummies(moth)

prev_uate_dates = d_tet_x.index - datie.timedelta(das=91) # Build the model

``````si1 = d_rin.loc[(d_tin['store'] == 1) & (_tran['ie'] == 1), 'ses']
exog_s1i1 = df_train.loc[(df_train['store'] == 1) & (df_train['item'] ==

ax = SARIMAX(si1.loc['2013-12-31':], exog=exog
nfoceinvetiblity=alse,enforce_ationarity=False, `````` ## Make predictions

``````
nog = df_rai.loc[(ftrin['str'] == s) & (df_rin['te'] == i), 'als']

SARIMAX(endog=edog exog=xo,
enorce_invtiilit=False, eorce_statnarityFalse, freq='D',
order=(7,0,0)).fit()

tc = time.time()``````   # Example forecast

``````xg = f_rin.loc[(df_rin[ste'] == 10) & (d_tri['itm'] == 50)].drop(['', 'ite', 'sas'], axis=1)
forast = arax.predict``````  The most popular insights