How to forecast a time series using exponential smoothing in R?

This recipe helps you forecast a time series using exponential smoothing in R

Recipe Objective

Exponential smoothing is a quantitative method of forecasting a time series data by using an exponential window function. In this method, the weights decrease exponentially in the exponential function. The recent values are given greater weights while the older wvalues are given lesser weights.

This method is quite intuitive and cis applied to huge range of time series data. There are many types of exponential smoothing but we are only going to discuss simple exponential smoothing in this recipe. ​

Simple Exponential smoothing technique is used when the time series data has no trend or seasonal variation. The weight of each and every parameter is always determined by alpha value described below: ​

𝐹𝑡 = 𝐹(𝑡−1) + α(𝐴(𝑡−1) – 𝐹(𝑡−1)

where:

  1. 𝐹_𝑡 =New Forecast
  2. 𝐹_(𝑡−1) = previous period forecast
  3. α = smoothing constant ( 0 ≤ α ≤ 1)
  4. 𝐴_(𝑡−1) = previous period’s actual demand

In this recipe, we will carry out simple exponential smoothing on amazon stock data ​

Get Access to Time Series Analysis Real World Projects in Python

STEP 1: Load necessary package

# for data manipulation library(tidyverse) # to get the stock data install.packages("fpp2") library(fpp2)

STEP 2: Get the google stock data

google.train = window(goog, end = 900) google.tst = window(goog, start = 901)

STEP 3: Performing Simple Exponential Smoothing

We will use the ses(train_data, alpha = , h = forecast forward steps) function to carry out the task

ses_google = ses(google.train, alpha = 0.3, # alpha value to be 0.3 h = 100) autoplot(ses_google)

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed