Skip to content

Instantly share code, notes, and snippets.

@pkgandhi
Last active August 5, 2020 01:27
Show Gist options
  • Save pkgandhi/721d7bf5c18924f5d3e115be10d62ead to your computer and use it in GitHub Desktop.
Save pkgandhi/721d7bf5c18924f5d3e115be10d62ead to your computer and use it in GitHub Desktop.
Fitting the AR and MA Models
# Loading the packages
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX
# Loading the data
data = pd.read_csv('https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv')
# Setting the month as index
data = data.set_index('Month')
# Plot the data
data.plot()
# Achieving stationarity:
data_log_transformation = np.log(data)
data_rolling_avg = data_log_transformation.rolling(window = 12).mean()
(data_log_transformation - data_rolling_avg).plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment