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.

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 data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

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, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

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

In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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