"This tutorial will guide your through predicting orders in ERP5 using an ARIMA model. The orders will be exported by ERP5 in CSV format (comma-sepparated values), and accessed and processed localy in a Jupyter Notebook.\n",
"This tutorial will guide your through predicting orders in ERP5 using an ARIMA model. The orders will be exported by ERP5 in CSV format (comma-sepparated values), and accessed and processed locally in a Jupyter Notebook.\n",
"\n",
"\n",
"Please note that **Pandas** and **NumPy** can also be used inside ERP5 Wendelin software release, but Jupyter notebook adds more convenient. Soon ERP5 integration with Jupyter will be released and merged into Wendelin software release, which will make everything much easier."
"Please note that **Pandas** and **NumPy** can also be used inside ERP5 Wendelin software release, but Jupyter notebook adds more convenience. Soon ERP5 integration with Jupyter will be released and merged into Wendelin software release, which will make everything much easier."
]
]
},
},
{
{
...
@@ -64,7 +64,7 @@
...
@@ -64,7 +64,7 @@
"source": [
"source": [
"# Check the sample data\n",
"# Check the sample data\n",
"\n",
"\n",
"Now you can go to the Sales Order Module and take a look at the generated sale orders. If you don't see any Sale Order there add a filter to see orders with the 'planned' status by writting in the first row of the table in the 'Status' column: '%planned%'. You should have something like the picture below.\n",
"Now you can go to the Sales Order Module and take a look at the generated sale orders. If you don't see any Sale Order there add a filter to see orders with the 'planned' status by writing in the first row of the table in the 'Status' column: '%planned%'. You should have something like the picture below.\n",
"In order to create a time series of orders we must create the report of the past orders to be used by the method. So we need to create a new Z SQL Method. You must go to the 'custom' folder in 'portal_skins' (`https://<your_instance_url>/portal_skins/custom/manage`), click in 'Add' and then in 'Z SQL Method'. Use 'SaleOrderModule_zGetStock' as SQL Method ID.\n",
"In order to create a time series of orders we must create the report of the past orders to be used by the method. So we need to create a new Z SQL Method. You must go to the 'custom' folder in 'portal_skins' (`https://<your_instance_url>/portal_skins/custom/manage`), click on 'Add' and then in 'Z SQL Method'. Use 'SaleOrderModule_zGetStock' as SQL Method ID.\n",
"\n",
"\n",
"Then you will type the following query:\n",
"Then you will type the following query:\n",
"\n",
"\n",
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
"source": [
"source": [
"# Exporting the sample data as CSV (extension)\n",
"# Exporting the sample data as CSV (extension)\n",
"\n",
"\n",
"To export the sample data as CSV you will navigate to `https://<your_instance_url>/portal_components`, click in the 'Action' box and select 'Add Extension Component'. Use 'extension.erp5.InventoryCsv' as ID and 'InventoryCsv' as reference.\n",
"To export the sample data as CSV you will navigate to `https://<your_instance_url>/portal_components`, click on the 'Action' box and select 'Add Extension Component'. Use 'extension.erp5.InventoryCsv' as ID and 'InventoryCsv' as reference.\n",
"\n",
"\n",
"Now you can copy the code below to your extension.\n",
"Now you can copy the code below to your extension.\n",
"\n",
"\n",
...
@@ -127,7 +127,7 @@
...
@@ -127,7 +127,7 @@
"source": [
"source": [
"# Exporting the sample data as CSV (external method)\n",
"# Exporting the sample data as CSV (external method)\n",
"\n",
"\n",
"Then you will need to create an external method to call your extension and run the export code. Navigate again to the 'custom folder' inside 'portal_skins', click 'Add' and choose 'External Method'. Now choose 'getInventoryCsv' as ID, 'InventoryCsv' as 'Module Name' and 'inventory_csv' as 'Function Name'. Click 'Save changes'."
"Then you will need to create an external method to call your extension and run the exportation code. Navigate again to the 'custom' folder inside 'portal_skins', click on 'Add' and choose 'External Method'. Now choose 'getInventoryCsv' as ID, 'InventoryCsv' as 'Module Name' and 'inventory_csv' as 'Function Name'. Click on 'Save changes'."
]
]
},
},
{
{
...
@@ -136,13 +136,13 @@
...
@@ -136,13 +136,13 @@
"source": [
"source": [
"# Preparing Jupyter\n",
"# Preparing Jupyter\n",
"\n",
"\n",
"Now we need to install Jupyter and all the used eggs to process the data localy. Just install the packages using 'pip' as below:\n",
"Now you need to install Jupyter and all the Python libraries to process the data locally. Just install the packages using 'pip' as below:\n",
"When the instalation finished you should be able to start Jupyter notebook server by running `jupyter notebook`. \n",
"When the instalation is finished you should be able to start Jupyter notebook server by running `jupyter notebook`. \n",
"\n",
"\n",
"Then you create a notebook called \"order prediction with ARIMA\", select \"Python 2\" as kernel and open the notebook to edit. "
"Then you create a notebook called \"order prediction with ARIMA\", select \"Python 2\" as kernel and open the notebook to edit. "
]
]
...
@@ -153,7 +153,7 @@
...
@@ -153,7 +153,7 @@
"source": [
"source": [
"# Basic Jupyter imports and setup\n",
"# Basic Jupyter imports and setup\n",
"\n",
"\n",
"To start working with Jupyter you need a few imports and some setup first. So you activate `matploblib` inline plotting to allow Jupyter to render beautiful charts inside Jupyter. Then you import some basics modules: csv, requests (to make a request to ERP5 and get the csv data), ggplot and matplotplib (to customize and improve plots styling), pandas, the plot object from matplotlib, statsmodels' api and StringIO. See the code below."
"To start working with Jupyter you need a few imports and some setup first. So you activate `matploblib` inline plotting to allow Jupyter to render beautiful charts inside Jupyter. Then you import some basic modules: csv, requests (to make a request to ERP5 and get the csv data), matplotplib (to customize the backend), pandas, the plot object from matplotlib, statsmodels' api and StringIO. See the code below."
]
]
},
},
{
{
...
@@ -240,7 +240,7 @@
...
@@ -240,7 +240,7 @@
"source": [
"source": [
"# Check if series is stationary\n",
"# Check if series is stationary\n",
"\n",
"\n",
"ARIMA models requires that the time series is stationary to give good predictions. A data series is stationary when its statiscal properties, like mean, variance, autocorrelation, and etc are all constant over time. You can check it just be looking at the plotted data, but you can also use the **Augmented Dicker-Fuller** test to have a more precise analysis. \n",
"ARIMA models requires that the time series is stationary to give good predictions. A data series is stationary when its statiscal properties, like mean, variance, autocorrelation, and etc are all constants over time. You can check this just by looking at the plotted data, but you can also use the **Augmented Dicker-Fuller** test to have a more precise analysis. \n",
"\n",
"\n",
"Using the Augmented Dicker-Fuller you need to get an **adf statistic** value __smaller__ (more negative) than the critical value at 5% for regression **c** (constant), **ct** (constant and trend), **ctt** (constant and quadratic trend)."
"Using the Augmented Dicker-Fuller you need to get an **adf statistic** value __smaller__ (more negative) than the critical value at 5% for regression **c** (constant), **ct** (constant and trend), **ctt** (constant and quadratic trend)."
]
]
...
@@ -294,7 +294,7 @@
...
@@ -294,7 +294,7 @@
"source": [
"source": [
"# Statistical analysis (auto correlation and partial auto correlation)\n",
"# Statistical analysis (auto correlation and partial auto correlation)\n",
"\n",
"\n",
"Now you need to idenfity which ARIMA model order fits better your data. So you will need to plot both the auto correlation and partial correlation graphs and make an analysis on them. 'statsmodels' provide easy to use method to plot both these graphs. Use the snippet below to do it."
"Now you need to idenfity which ARIMA model order fits better your data. So you will need to plot both the auto correlation and partial correlation graphs and analyse them. 'statsmodels' provide an easy to use method to plot both these graphs, check the snippet below."
]
]
},
},
{
{
...
@@ -339,7 +339,7 @@
...
@@ -339,7 +339,7 @@
"source": [
"source": [
"Looks like partial auto correlation goes to 0 after lag 3. So **ARMA(3,0)** looks like an adequated model for our data. Auto correlation graph shows information about another model that might be good but require a different analysis, which isn't the real focus of this tutorial.\n",
"Looks like partial auto correlation goes to 0 after lag 3. So **ARMA(3,0)** looks like an adequated model for our data. Auto correlation graph shows information about another model that might be good but require a different analysis, which isn't the real focus of this tutorial.\n",
"\n",
"\n",
"An important thing to note is that there are mathmetical methods to have suggestion of model orders for the data. You will get to know them in the next section."
"An important thing to note is that there are mathematical methods to give suggestions of model orders for your data. You will get to know them in the next section."
]
]
},
},
{
{
...
@@ -348,7 +348,7 @@
...
@@ -348,7 +348,7 @@
"source": [
"source": [
"# Minimum order sugestion for ARMA modelling\n",
"# Minimum order sugestion for ARMA modelling\n",
"\n",
"\n",
"'statsmodels' also has useful methods to give mathmetical suggestions for ARMA models order. This method can use different information criteria to make its decision. You will use the Akaike Information Criteria (aic) for this tutorial."
"'statsmodels' also has useful methods to give mathmetical suggestions for ARMA models order. This method can use different information criterias to make its decision. You will use the Akaike Information Criteria (aic) for this tutorial."
]
]
},
},
{
{
...
@@ -416,7 +416,7 @@
...
@@ -416,7 +416,7 @@
"source": [
"source": [
"# Fitting and checking residuals\n",
"# Fitting and checking residuals\n",
"\n",
"\n",
"Now you need to check the residuals to confirm if it looks like white noise. If residuals in fact look like white noise it means your prediction is statiscally good. To do this you plot the autocorrelation and partial autocorrelation of the residuals and verify if they are under the confidence limits (blue shadow) and also wether they look like a periodic function."
"Now you need to check the residuals to confirm if it looks like white noise. If residuals in fact look like white noise it means your prediction is statiscally good. To do this you plot the autocorrelation and partial autocorrelation of the residuals and verify if they are under the confidence limits (blue shadow) and also whether they look like a periodic function."