The process of Estimating future sales revenue is known sales forecasting. It is an essential step in budgeting and strategic planning because it enables businesses to foresee demand in the future and make wise choices about inventory, staffing, and investments. We will examine how to create a sales forecast, what a sales forecast is, why it serves as the foundation for budgeting, and how to increase its accuracy in this article.
Data collection is the first step in producing a sales forecast. This includes data on previous sales, market trends, and any outside elements that might affect sales, such as alterations in the economy or rivalry. After gathering this information, you can use it to make a baseline forecast. There are numerous techniques for predicting sales,, including trend analysis, seasonal analysis, and causal analysis.
Trend analysis looks at historical sales data to identify patterns and trends, such as whether sales tend to increase or decrease over time. Seasonal analysis looks at how sales fluctuate over the course of a year, taking into account factors such as holidays or weather. Causal analysis looks at the relationship between sales and external factors, such as changes in the economy or competition.
Once you have created a baseline forecast, it’s important to review it and make any necessary adjustments. This includes considering any changes in the business environment, such as new competitors or changes in consumer behavior. It’s also important to review the assumptions that were used to create the forecast, as these can have a significant impact on the accuracy of the forecast.
One key factor that can improve the accuracy of a sales forecast is using advanced Machine learning tools like python, Tableau, and R, which are widely used by businesses of all sizes.
Python is a powerful programming language that is widely used in data science and machine learning, and it offers a variety of tools and libraries for sales forecasting. One popular library for sales forecasting in python is Prophet, which is an open-source library developed by Facebook. Prophet is a time series forecasting library that uses a decomposable time series model with three main components: trend, seasonality, and holidays. It’s easy to use, and it can handle missing data, outliers, and large numbers of changepoints. Another popular method for sales forecasting using python is by building models like ARIMA, LSTM and Random Forest etc. These models can be used to analyze historical sales data and make predictions based on that data.
In This article we will learn how we can use FB prophet to forecast because this the simplest method any one can do it you don’t need to have any hardcore statistical knowledge offcourse if you have it then it will be great because you can do experiments with but for basic predictions, it is not requitred.
Lets start with the process.
- First, install the fbprophet library by running “!pip install fbprophet” in your command line or terminal.
- Next, import the necessary libraries: Panadas, Numpy, prophet
[wpsm_box type=”blue” float=”none” textalign=”left”]
!pip install prophet
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from prophet.plot import plot_plotly, plot_components_plotly
import prophet
from prophet import Prophet
[/wpsm_box]
3.Upload the sales data in Excel by following code
[wpsm_box type=”blue” float=”none” textalign=”left”]
from google.colab import files
uploaded = files.upload()
[/wpsm_box]
4.Check your data
[wpsm_box type=”blue” float=”none” textalign=”left”]
df = pd.read_excel(‘salesdata1.xls’)
df
[/wpsm_box]
Date | Sales | |
0 | 2016-11-08 | 993.9000 |
1 | 2016-06-12 | 2962.5630 |
2 | 2015-10-11 | 1011.8955 |
3 | 2014-06-09 | 5463.0080 |
4 | 2017-04-15 | 332.3380 |
… | … | … |
1232 | 2015-12-29 | 6.3600 |
1233 | 2014-04-03 | 233.4500 |
1234 | 2016-06-03 | 71.0880 |
1235 | 2015-04-12 | 40.7400 |
1236 | 2014-01-21 | 25.2480 |
1237 rows × 2 columns
5.Prepare your data in a format that Prophet understands. The data should have two columns: ‘ds’ and ‘y’. Where ‘ds’ represents the date or time and ‘y’ represents the value you want to forecast. For example:
[wpsm_box type=”blue” float=”none” textalign=”left”]
df.columns =[‘ds’,’y’]
df
[/wpsm_box]
ds | y | |
0 | 2016-11-08 | 993.9000 |
1 | 2016-06-12 | 2962.5630 |
2 | 2015-10-11 | 1011.8955 |
3 | 2014-06-09 | 5463.0080 |
4 | 2017-04-15 | 332.3380 |
… | … | … |
1232 | 2015-12-29 | 6.3600 |
1233 | 2014-04-03 | 233.4500 |
1234 | 2016-06-03 | 71.0880 |
1235 | 2015-04-12 | 40.7400 |
1236 | 2014-01-21 | 25.2480 |
1237 rows × 2 columns
6.Let see How our data looks like
[wpsm_box type=”blue” float=”none” textalign=”left”]
df[‘y’].plot()
[/wpsm_box]
7.Create an instance of the Prophet model and fit it to your data:
[wpsm_box type=”blue” float=”none” textalign=”left”]
m = Prophet()
m.fit(df)
[/wpsm_box]
8.Create a dataframe for future dates to forecast the revenue:(We will forecast for next 365 days)
[wpsm_box type=”blue” float=”none” textalign=”left”]
future = m.make_future_dataframe(periods = 365)
[/wpsm_box]
10.Use the predict method to generate forecasted values:
[wpsm_box type=”blue” float=”none” textalign=”left”]
forcast = m.predict(future)
[/wpsm_box]
11.Since there are many columns the forecast dataframe that we don’t need we will filter the dataframe and keep only four colums ds’,’yhat’,’yhat_lower’,’yhat_upper’
Where
ds = date
[wpsm_box type=”blue” float=”none” textalign=”left”]
forcast[[‘ds’,’yhat’,’yhat_lower’,’yhat_upper’]]
[/wpsm_box]
ds | yhat | yhat_lower | yhat_upper | |
0 | 2014-01-03 | 1548.089552 | -1154.963054 | 4316.623895 |
1 | 2014-01-04 | 1053.291908 | -1649.573434 | 3819.991523 |
2 | 2014-01-05 | 1144.800915 | -1699.492962 | 3871.013814 |
3 | 2014-01-06 | 1269.907825 | -1504.028849 | 4078.835022 |
4 | 2014-01-07 | 612.409537 | -2214.119793 | 3664.435142 |
… | … | … | … | … |
1597 | 2018-12-26 | 2153.549394 | -669.818649 | 4918.112296 |
1598 | 2018-12-27 | 3253.475239 | 527.863105 | 6030.005657 |
1599 | 2018-12-28 | 3415.948439 | 861.819770 | 6226.124080 |
1600 | 2018-12-29 | 2913.078091 | 256.325953 | 5601.628304 |
1601 | 2018-12-30 | 2987.585403 | 182.011405 | 5861.705644 |
1602 rows × 4 columns
12.Plot the forecasted revenue:
[wpsm_box type=”blue” float=”none” textalign=”left”]
plot_plotly(m,forcast)
[/wpsm_box]
13.Plot the forecasted revenue with uncertainty intervals:(Trend analysis at different time intervals)
[wpsm_box type=”blue” float=”none” textalign=”left”]
plot_components_plotly(m,forcast)
[/wpsm_box]
This was a very simple model, you can toggle around with the model, changing variables like seasonality or adding new regressor on which revenue depends.