Monday 4 December 2017

Demand Forecasting:Time Series Smoothing and Holt- Winters Technique


Demand Forecasting:Time Series Smoothing and Holt- Winters Technique

Introduction

In this time series article wherein I will apply techniques like couple of types of smoothing, smoothing filtering and prediction estimating the past present and future.

We will cover major types of moving averages and use Holt Winters technique which is a single Exponential smoothing technique. We will majorly cover Holt Winter forecasting method. The Holt-Winters seasonal method comprises the forecast equation and three smoothing equations — one for the level â„“ t , one for trend b t , and one for the seasonal component denoted by s t , with smoothing parameters α , β ∗ and γ

Now we will look at the head and sample of the data

Now we will look the summary of the data

summary(mydata)
##       date             orders_count  
##  Min.   :2017-09-28   Min.   : 3.00  
##  1st Qu.:2017-10-04   1st Qu.: 7.75  
##  Median :2017-10-11   Median :14.50  
##  Mean   :2017-10-11   Mean   :15.18  
##  3rd Qu.:2017-10-18   3rd Qu.:21.25  
##  Max.   :2017-10-25   Max.   :35.00

The data is free from missing values. Now lets plot the data

plot.ts(mydata$orders_count,type="l",las=2,main="Plot of daily sales",xlab="Days",ylab="Order Count/No of sales")
grid()

The data consist of one month data starting from 28th Sep 2017 to 25th Oct 2017.

Now we will look at number of customers visit day wise.

data2<-mydata
data.days<-wday(as.Date(mydata$date,'%d-%m-%Y'), label=TRUE)
data5<-cbind(data2,data.days)
sub_group<-group_by(data5,data.days)
summarise(sub_group,total=sum(orders_count))
## # A tibble: 7 x 2
##   data.days total
##       <ord> <int>
## 1       Sun    80
## 2       Mon    60
## 3       Tue    50
## 4       Wed    20
## 5       Thu    40
## 6       Fri    75
## 7       Sat   100

We got a understanding that on Friday, Saturday and Sunday the customer footfall is high and least on Wednesday, Thursday and Tuesday.

When we look at the data we find the data is having noise. we will reduce it by smoothing. We can do smoothing by SMA,EMA, WMA etc.. We will perform SMA and EMA later use EMA to predict the data.

What is smoothing?

When data collected over time displays random variation, smoothing techniques can be used to reduce or cancel the effect of these variations. When properly applied, these techniques smooth out the random variation in the time series data to reveal underlying trends.

Simple Moving Average Smoothing

It is applied for non-complex time series data where the fluctuation of the data is high. It follow average and thus put equal weights on each every observation and thus it is more likely to under-smoothing and over-smoothing.

d_SMA<-SMA(mydata$orders_count,n=3)
plot.ts(mydata$orders_count,type="l",las=2, main="Simple Moving Average Smoothing",xlab="Time",ylab="Sales")
lines(d_SMA,col="green")

The green line is the predicted data with 3 day average. i.e ((day1+day2+day3)/3)

But this can be applied to understand the crux of the data and help to avoid randomness in the data. It is normally applied to all types of the data but it do not have better predictability on seasonal and the data with weights.

Exponential Moving Average Smoothing

In Exponential Smoothing we use include** alfa parameter** which is a link between actual and predicted. More the alfa more it is near to actual and less the alfa far from the actual where alfa is between 0 to 1. Exponential Smoothing should only be used when the data set contains no seasonality. The forecast is a constant value that is the smoothed value of the last observation.

sales1<-HoltWinters(mydata$orders_count,alpha = 0.6,beta = FALSE,gamma = FALSE)
sales_pred1<-predict(sales1,n.ahead=10,prediction.interval = TRUE)
plot(sales1,sales_pred1,main = "Exponential Moving Average with Prediction")

The red line is the EMA line and black is the actual line and blue lines are the upper and lower limts

Double Exponential Smoothing

Alike Exponential smoothing, we use Alfa but along with it we also use beta parameter to predict. Beta is a trend component and can used when there is a strong implication of trend continuity.

sales2<-HoltWinters(mydata$orders_count,alpha = 0.6,beta = 0.9,gamma = FALSE)
sales_pred2<-predict(sales2,n.ahead=10,prediction.interval = TRUE)
plot(sales2,sales_pred2,main="Prediction with Alpha and Beta")

Here I have increased beta to 0.90 (Beta) which say there is 90% change the trend will continue.

Holt Winter Techniques

When we take Holt Winters it consist of 3 models multiplicative, damped and addictive. Addictive model is a default in R and Multiplicative need to be mentioned as seasonal= multiplicative. As we are covering seasonal we will majorly concentrate on addictive and multiplicative.

We Will look at Multiplicative seasonal model

sales_fq<-ts(mydata$orders_count,frequency = 4)
sales4<-HoltWinters(sales_fq,seasonal = "multiplicative")
sales_pred4<-predict(sales4,n.ahead=7,prediction.interval = TRUE)
plot(sales4,sales_pred4,main = "Multiplicative Holt-Winters Model")

we will look at the Addictive Seasonal Model

sales5<-HoltWinters(sales_fq)
sales_pred5<-predict(sales5,n.ahead = 10,prediction.interval = TRUE)
plot(sales5,sales_pred5,main = "Addictive Holt Winter Model")

Going furhter we can change the inner parameter in the data for better predictability.

No comments:

Post a Comment