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

2022-07-25 12:59:3551CTO

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

1.

2.

3.

4.

```

```

d_ts = pd.ra_csv'../iputst.csv', prse_des=['date'], ine_col['d

1.

2.

```   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)

1.

2.

3.

4.

``` ```

import datetime

dumymns = pd.get_dummies(moth)

prev_uate_dates = d_tet_x.index - datie.timedelta(das=91)

1.

2.

3.

4.

5.

6.

``` ## 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,

1.

2.

3.

4.

5.

6.

``` ### 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()

1.

2.

3.

4.

5.

6.

7.

8.

```   ## Example forecast

```

xg = f_rin.loc[(df_rin[ste'] == 10) & (d_tri['itm'] == 50)].drop(['', 'ite', 'sas'], axis=1)

forast = arax.predict

1.

2.

```  