pinterest
Icon1 Icon2 Icon3 Icon4

DATA SCIENCE

using PYTHON

LIVE ONLINE TRAINING

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 revenue
  • Xi = Time coding
  • b0 = Base year trend
  • b1 = Annual change
  • Forecast future values using the same formula.

Ŷi+1 = b0 + b1Xi+1

Quadratic Trend Model:

Ŷi = b0 + b1Xi + b2Xi2

  • Ŷi, Xi, Xi2, b0, b1, b2 explained here

  • Use the equation to forecast future values.

Ŷi+1 = b0 + b1Xi+1 + b2X2i+1

Exponential Trend Model:

Log (Ŷi) = b0 + b1Xi

  • Includes logarithmic transformation of the model

β0 = antilog(b0)

β1 = antilog(b1)

Ŷi = (β0) (β1)X

Forecast = Ŷi+1 = (β0) (β1)X+1

  • β1×100% = Annual compound growth rate

Implementation of Trend Fitting Models using Python:

In [25]:

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": "Real_Revenue"})

eastmank_revenue.head()

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