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 = b0 + b1XiŶi = Predicted value for revenue at time i
Xi = 0 for the first year, 1 for the second year, 3 for the third year and so on
b0 = Fitted trend value reflecting the predicted mean during the base year or first year (0)
b1 = Average change in Ŷi per year
You can also use the above equation to make forecast of any future vales.
Ŷi+1 = b0 + b1Xi+1Quadratic Trend Model
Ŷi = b0 + b1Xi + b2Xi2Ŷi = Predicted value for revenue at time i
Xi = 0 for the first year, 1 for the second year, 3 for the third year and so on
Xi2 = Quadratic trend effect
b0 = Fitted trend value reflecting the predicted mean during the base year or first year (0)
b1 = Average change in Ŷi per year
b2 = Average change in Ŷi due to quadratic trend effect
You can also use the above equation to make forecast of any future vales.
Ŷi+1 = b0 + b1Xi+1 + b2X2i+1Exponential Trend Model:
Log (Ŷi) = b0 + b1XiHere, it includes Log so our parameters (b0, b1) are on log scale. So,
β0 = antilog(b0)β1 = antilog(b1)
Hence,
Ŷi = (β0) (β1) XForecast = Ŷ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 |
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 |
---|