This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_len = int(len(ts_sun) * 0.2) | |
sun_train, sun_test = ts_sun.iloc[:-test_len], ts_sun.iloc[-test_len:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
import warnings | |
warnings.filterwarnings("ignore") | |
# adapted from https://www.kaggle.com/kashnitsky/topic-9-part-1-time-series-analysis-in-python?scriptVersionId=50985180&cellId=80 | |
def tsplot(y, lags=None, figsize=(12, 7)): | |
""" | |
Plot time series, its ACF and PACF, calculate Dickey–Fuller test | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ts_sun_diff = (ts_sun - ts_sun.shift(1)).dropna() | |
tsplot(ts_sun_diff) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.api as sm | |
data = sm.datasets.sunspots.load_pandas() | |
ts_sun = data.data.set_index('YEAR').SUNACTIVITY | |
ts_sun.plot(figsize=(12, 5)) | |
plt.show() |
NewerOlder