MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to forecast a time series using exponential smoothing?

# How to forecast a time series using exponential smoothing?

This recipe helps you forecast a time series using exponential smoothing

We can note that both Simple average and Weighted moving average lie on completely opposite ends. We would need something between these two extremes approaches which takes into account all the data while weighing the data points differently. It can be best done by exponential smoothing.

So this recipe is a short example on forecast a time series using exponential smoothing. Let's get started.

```
import numpy as np
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA
from statsmodels.tsa.holtwinters import SimpleExpSmoothing
```

Let's pause and look at these imports. Numpy and pandas are general ones. Here statsmodels.tsa.holtwinters is used to import SimpleExpSmoothing library for building of model.

```
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'])
df.head()
```

Here, we have used one time series data from github.

Now our dataset is ready.

```
train_data = df[1:len(df)-12]
test_data = df[len(df)-12:]
```

Here we have simply split data into size of 12 and rest elements

```
model = SimpleExpSmoothing(train_data.value)
model_fitted = model.fit()
```

A simple model of exponential smoothing has been created in here for building our model on train values.

```
print('coefficients',model_fitted.params)
predictions = model_fitted.predict(start=len(train_data), end=len(train_data) + len(test_data)-1)
print(predictions)
```

Here, we have printed the coeffiecient of model and the predicted values.

Once we run the above code snippet, we will see:

Scroll down the ipython file to visualize the output.

Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

In this project, we are going to work on Deep Learning using H2O to predict Census income.

In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Datasetâ€‹ using Keras in Python.