import plotly
plotly.offline.init_notebook_mode()
import pandas as pd
df=pd.read_csv('weatherAUS.csv', encoding='utf-8', usecols=['Date', 'Location', 'MinTemp'])
df = df[df['Location'] == 'Albury']
import plotly.express as px
fig = px.line(df, x='Date', y='MinTemp')
fig.show()
from statsmodels.tsa.holtwinters import SimpleExpSmoothing
training = df['MinTemp'][:10]
model = SimpleExpSmoothing(training)
model_fit = model.fit(smoothing_level=0.4,optimized=True)
# conduct in sampe prediction
# conduct out of sample prediction on t+1
df['predict'] = model_fit.predict(start=0, end = 10) # 0-9 in sample prediction; 10 out of sample prediction
fig = px.line(df.iloc[:11], x='Date', y=['MinTemp', 'predict'])
fig.show()
training = df['MinTemp'][:10]
from statsmodels.tsa.api import Holt
model = Holt(training)
model_fit = model.fit(smoothing_level=0.8, smoothing_trend=0.2, optimized=False)
df['predict'] = model_fit.predict(start=0, end = 12)
fig = px.line(df.iloc[:13], x='Date', y=['MinTemp', 'predict'])
fig.show()
import numpy as np
pd.DataFrame(np.c_[model_fit.level,model_fit.trend]).rename(columns={0:'level',1:'slope'}).plot(subplots=True)
array([<Axes: >, <Axes: >], dtype=object)
from statsmodels.tsa.holtwinters import ExponentialSmoothing
training = df['MinTemp'][:10]
model = ExponentialSmoothing(training, seasonal_periods=2, trend='add', seasonal='add')
model_fit = model.fit(smoothing_level=0.8,smoothing_trend=0.2, smoothing_seasonal=0.8)
df['predict'] = model_fit.predict(start=0, end = 12)
fig = px.line(df.iloc[:13], x='Date', y=['MinTemp', 'predict'])
fig.show()
import numpy as np
pd.DataFrame(np.c_[model_fit.level, model_fit.trend, model_fit.season]).rename(columns={0:'level',1:'slope', 2:'season'}).plot(subplots=True)
array([<Axes: >, <Axes: >, <Axes: >], dtype=object)