Professional Documents
Culture Documents
import numpy as np
%matplotlib inline
uploaded = files.upload()
data.head()
0 1949-01 112
1 1949-02 118
2 1949-03 132
3 1949-04 129
4 1949-05 121
con=data['Month']
data['Month']=pd.to_datetime(data['Month'])
data.set_index('Month', inplace=True)
data.index
'1949-09-01', '1949-10-01',
...
'1960-11-01', '1960-12-01'],
dtype='datetime64[ns]', name='Mont
h', length=144, freq=None)
In [ ]: ts = data['#Passengers']
ts.head(10)
Month
Out[ ]:
1949-01-01 112
1949-02-01 118
1949-03-01 132
1949-04-01 129
1949-05-01 121
1949-06-01 135
1949-07-01 148
1949-08-01 148
1949-09-01 136
1949-10-01 119
In [ ]: plt.plot(ts)
[<matplotlib.lines.Line2D at 0x7ff7a315d110>]
Out[ ]:
rolstd = ts.rolling(13).std()
plt.plot(ts, color='blue',label='Original')
In [ ]: ts_log=np.log(ts)
plt.plot(ts_log)
[<matplotlib.lines.Line2D at 0x7ff7a2bb2490>]
Out[ ]:
# print(moving_avg.dtypes)
# plt.plot(ts_log,label='Original')
# plt.plot(moving_avg, color='red',label='Rolling M
# plt.legend()
float64
<matplotlib.legend.Legend at 0x7ff7a2b2c4d0>
Out[ ]:
In [ ]: # ts_log_moving_avg_diff=ts_log-moving_avg
# ts_log_moving_avg_diff.head(13)
Month
Out[ ]:
1949-01-01 NaN
1949-02-01 NaN
1949-03-01 NaN
1949-04-01 NaN
1949-05-01 NaN
1949-06-01 NaN
1949-07-01 NaN
1949-08-01 NaN
1949-09-01 NaN
1949-10-01 NaN
1949-11-01 NaN
1949-12-01 NaN
1950-01-01 NaN
In [ ]: # ts_log_moving_avg_diff.dropna(inplace=True)
# ts_log_moving_avg_diff.head(10)
# moving_avg= ts_log_moving_avg_diff.rolling(13).me
In [ ]: # plt.plot(ts_log_moving_avg_diff,label='Original')
# plt.plot(moving_avg,color='red',label='Rolling Me
# plt.legend()
In [ ]: ts_log_diff=ts_log-ts_log.shift()
plt.plot(ts_log_diff)
[<matplotlib.lines.Line2D at 0x7ff78e8a61d0>]
Out[ ]:
In [ ]: ts_log_diff.dropna(inplace=True)
moving_avg= ts_log_diff.rolling(13).mean()
plt.plot(ts_log_diff)
plt.plot(moving_avg,color='red',label='Rolling Mean
plt.legend()
<matplotlib.legend.Legend at 0x7ff78e95db90>
Out[ ]:
model=ARIMA(ts_log_diff,order=(2,1,2))
results_ARIMA=model.fit(disp=-1)
plt.plot(ts_log_diff,label='Original')
plt.plot(results_ARIMA.fittedvalues,color='red',lab
plt.legend()
/usr/local/lib/python3.7/dist-packages/statsmodel
s/tsa/base/tsa_model.py:165: ValueWarning: No freq
uency information was provided, so inferred freque
ncy MS will be used.
% freq, ValueWarning)
/usr/local/lib/python3.7/dist-packages/statsmodel
s/tsa/base/tsa_model.py:165: ValueWarning: No freq
uency information was provided, so inferred freque
ncy MS will be used.
% freq, ValueWarning)
/usr/local/lib/python3.7/dist-packages/statsmodel
s/base/model.py:492: HessianInversionWarning: Inve
rting hessian failed, no bse or cov_params availab
le
'available', HessianInversionWarning)
<matplotlib.legend.Legend at 0x7ff78e8eaf10>
Out[ ]:
In [ ]:
In [ ]: