-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass1.py
More file actions
56 lines (48 loc) · 1.33 KB
/
Copy pathclass1.py
File metadata and controls
56 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
Created on 14 de ago de 2019
@author: gusta
'''
# lib to handle with time series
from pandas import Series
# lib to plot the data
import matplotlib.pyplot as plt
# lib to use the decompositio in the time series
from statsmodels.tsa.seasonal import seasonal_decompose
# lib to use the acf and pcf correlations
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
# lib to organize the data in data frame
from pandas import DataFrame
# lib to organize the time series by periods
from pandas import TimeGrouper
# to read the time series
series = Series.from_csv('airline-passengers.csv', header=0)
series.plot()
plt.show()
# to plot by year
groups = series.groupby(TimeGrouper('A'))
years = DataFrame()
for name, group in groups:
years[name.year] = group.values
years.boxplot()
plt.show()
# to plot by month
groups = series.groupby(TimeGrouper('M'))
years = DataFrame()
for name, group in groups:
years[name.month] = group.values
years.boxplot()
plt.show()
# to decompose the time series
result = seasonal_decompose(series, model='multiplicative')
result.plot()
plt.show()
# to use the acf
plot_acf(series, lags=10)
plt.show()
# to use the pacf
plot_pacf(series, lags=10)
plt.show()
# to plot the acf above the residual time series
#result.trend; result.seasonal; result.resid; result.observed
plot_acf(result.resid, lags=10)
plt.show()