# Forecasting Parameter Optimization by Minimizing the Mean Square Error in Python

To Know more about the Different Corporate Training & Consulting Visit our website www.Instrovate.com Or Email : info@instrovate.com or WhatsApp / Call at +91 74289 52788

# Forecasting Parameter Optimization by Minimizing the Mean Square Error in Python

##### Share

Prerequisites To Follow this Exercise :

1. Python Installed in your System : If you are a new user to Python and want to know how to install Python via the Anaconda Distribution , You can go through the step by step Blog i have written to install Python via Anaconda Distribution & start using Jupyter Notebook : https://instrovate.com/2019/06/09/python-anaconda-distribution-how-to-download-and-install-it-and-run-the-first-python-program/

Once you have the  Python Installed in your system you are Good to Go ahead and follow the below Use Case and Example.

Consider the below data set stored as comma separated csv file.

Use the 2017 Data to predict the sales in the year 2018. For making prediction use Moving Average Algorithm. Use the following values for Window as a parameter in Moving Average Algorithm: {3, 4, 5, 6}.

For each of the above values of parameter compute the value of mean square error.

Plot the mean square error to select the value of Window based on least mean square value.

*********************************************************

Try On you Own First Before Referring to the Solution Below

***********************************************************

Here the first step is to store the sales data in python list.

SO, first we will create an empty list to store the sales data that exists in index 4 in the csv file.

Next is to read the csv file line by line and populate the empty list line by line.

We will use the previous code to solve this. The extra step would be to add another outer loop to iterate for different values of parameter i.e. Window for Moving Average Algorithm.

For each of the predictions made with respective value of Window the mean square error is being computed in each loop.

The mse is the list where all the mean square errors are being stored.  Here is the Code Snippet To Achieve the Desire Result. If you want to get the Code as Python Code File Subscribe to our website – https://instrovate.com/ and our YouTube Channel Below – https://youtube.com/c/InstrovateTechnologies