# DATA SCIENCE USING PYTHON

## ONLINE TRAINING COURSE

# Trend Fitting Models

Linear Trend, Quadratic Trend And Exponential Trend:

The component factor of a time series often studied is Trend. If you plot the data (say revenue) on vertical axis and time (say year) on horizontal axis, you will come to now the different trend (linear, quadratic and exponential) present in the series.

Parameters of the trend fitting models are estimated by using method of least square.

Here, we will model the revenue as a function of time based on different trend.

Linear Trend Model:

*Ŷ*

_{i}= b_{0}+ b_{1}X_{i}*Ŷ*= Predicted value for revenue at time i

_{i}*X*= 0 for the first year, 1 for the second year, 3 for the third year and so on

_{i}*b*= Fitted trend value reflecting the predicted mean during the base year or first year (0)

_{0}*b*= Average change in Ŷ

_{1}_{i}per year

You can also use the above equation to make forecast of any future vales.

*Ŷ*

_{i+1}= b_{0}+ b_{1}X_{i+1}Quadratic Trend Model

*Ŷ*

_{i}= b_{0}+ b_{1}X_{i}+ b_{2}X_{i}^{2}*Ŷ*= Predicted value for revenue at time i

_{i}*X*= 0 for the first year, 1 for the second year, 3 for the third year and so on

_{i}*X*= Quadratic trend effect

_{i}^{2}*b*= Fitted trend value reflecting the predicted mean during the base year or first year (0)

_{0}*b*= Average change in Ŷ

_{1}_{i}per year

*b*= Average change in Ŷ

_{2}_{i}due to quadratic trend effect

You can also use the above equation to make forecast of any future vales.

*Ŷ*

_{i+1}= b_{0}+ b_{1}X_{i+1}+ b_{2}X^{2}_{i+1}Exponential Trend Model:

*Log (Ŷ*

_{i}) = b_{0}+ b_{1}X_{i}Here, it includes Log so our parameters (b0, b1) are on log scale. So,

*β*

β

_{0}= antilog(b_{0})β

_{1}= antilog(b_{1})Hence,

*Ŷ*

Forecast = Ŷ

_{i}= (β_{0}) (β_{1})^{X}Forecast = Ŷ

_{i+1}= (β_{0}) (β_{1})^{X+1}In above equations, β_{1}×100% represents the estimated annual compound growth rate (in %)

In [25]:

Trend Fitting Models

import numpy as np

import pandas as pd
import matplotlib.pyplot as plt

import seaborn as sns
import math

# Load the input files

eastmank_revenue = pd.read_excel ("./Data/EASTMANK.XLS", sheet_name = "Data") [[ "Year" , "Real Revenue"]]

eastmank_revenue = eastmank_revenue.rename (columns = { "Real Revenue" :

Out [25]:

Year | Real_Revenue | |
---|---|---|

0 | 1975 | 9.3 |

1 | 1976 | 9.5 |

2 | 1977 | 9.9 |

3 | 1978 | 10.7 |

4 | 1979 | 11.0 |

__Implementtion of Trend Fitting Models using Python__

In [26]:

# Create coded year, quadratic and exponential variables

eastmank_revenue["coded_year"] = eastmank_revenue.index

eastmank_revenue["coded_year_square"] = eastmank_revenue["coded_year"] ** 2

eastmank_revenue["log_Real_Revenue"] = np.log (eastmank_revenue)["Real_Revenue"]

eastmank_revenue.head()

Out [26]:

Year | Real_Revenue | coded_year | coded_year_square | log_Real_Revenue |
---|