current position:Home>Python uses ARIMA and arimax to predict the time series data of store commodity sales demand

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.

Load data

      
      
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
  • 1.
  • 2.

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _r Language

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _ The time series _02

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _ The time series _03

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)
d_trin.head()
  • 1.
  • 2.
  • 3.
  • 4.

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _ The time series _04

      
      
import datetime

dumymns = pd.get_dummies(moth)

prev_uate_dates = d_tet_x.index - datie.timedelta(das=91)
dfetex.head()
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _r Language _05

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.



Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _ The time series _06

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.

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _pandas_07

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _ development language _08

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _ development language _09

Example forecast

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

Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _pandas_10


Python use ARIMA ,ARIMAX Time series data for predicting store commodity sales demand _r Language _11

copyright notice
author[51CTO],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/206/202207251232084136.html

Random recommended