# Plotting Actual Vs. Predicted Sales 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

# Plotting Actual Vs. Predicted Sales 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. Write a python program that can utilize 2017 Data set and make a prediction for the year 2018 for each month.

After Prediction plot the Actual Vs. predicted Sales for the purpose of visualization.

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

Try On you Own First Before Referring to the Solution Below

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

Solution :

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.
Once we have all the sales data we would create another empty list to store the predictions.
Now since we need to predictions for the next 12 months we would again iterate from index 12 to 24 (Since we already have data for index below 12).
Now under each iteration we will apply moving average algorithm to predict the current month’s sales.
The window of moving average is taken as 3.
WHile iterating through each point for which prediction is to be made we will populate another list called x_axis. This list will contain the index of each data point. This is required to plot the actual and predicted sales. When we plot something we need two axis x and y. THis list x_axis would serve as axis x against which actual sales and predicted sales will be plot.
Once the 12 months predictions are made. Then we will use another loop to print the actual sales vs. predicted sales.

The python and program and its output code snippet are as follows. 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