In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
airline = pd.read_csv('airline_passengers.csv',
index_col = "Month")
In [3]:
airline.head()
Out[3]:
In [4]:
airline.plot(figsize = (12, 8))
Out[4]:
We can use an additive model when it seems that the trend is more linear and the seasonality and trend components seem to be constant over time (e.g. every year we add 10,000 passengers). A multiplicative model is more appropriate when we are increasing (or decreasing) at a non-linear rate (e.g. each year we double the amount of passengers).
Based off this chart, it looks like the trend in these earlier days is slightly increasing at a higher rate than just linear (although it is a bit hard to tell from this one plot).
In [5]:
# Get data in correct format
airline.dropna(inplace=True)
airline.index = pd.to_datetime(airline.index)
In [6]:
airline.head()
Out[6]:
In [7]:
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(airline['Thousands of Passengers'],
model = 'multiplicative')
result.plot()
Out[7]:
In [8]:
# You may accidentally see two of the same plots here, not to worry,
# just a small bug with statsmodels function.