-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Youngsun-Lee-DS/main
chapter 4 update
- Loading branch information
Showing
62 changed files
with
2,561 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# 시계열의 특징 {#chap4} | ||
|
||
`feats`패키지에는 **FE**atures **A**nd **S**tatistics from **T**ime **S**eries를 | ||
computing하는 함수들이 있다. | ||
우리는 이미 시계열의 특징 몇가지를 앞에서 살펴보았다. | ||
예를 들면, autocorrelations(자기상관)이 시계열의 특징으로 제시되었다. | ||
|
||
## 몇가지 간단한 통계 | ||
|
||
features() 함수를 통해 평균, 최소값, 최댓값을 계산할 수 있다. | ||
|
||
### 평균 | ||
|
||
예를 들어, tourism 데이터(분기별 호주 여행객수)를 사용하여 **mean**으로 모든 시계열의 평균을 계산할 수 있다. | ||
|
||
```{r} | ||
tourism %>% | ||
janitor::clean_names() %>% | ||
features(trips, list(mean = mean)) %>% | ||
arrange(mean) | ||
``` | ||
South Australia 주에 있는 캥거루 섬을 방문한 평균 방문객 수가 가장 적었다는 것을 알 수 있다. | ||
|
||
### 사분위수 | ||
|
||
**quantile**을 통해 최소값, 제1사분위수, 중위수, 제3사분위수, 최대값을 계산할 수 있다. | ||
|
||
```{r} | ||
tourism %>% | ||
janitor::clean_names() %>% | ||
features(trips, quantile) | ||
``` | ||
0%는 최소값을 의미하고, 100%는 최대값을 의미한다. | ||
|
||
### ETC | ||
|
||
list()를 통해 평균과 최소값, 제1사분위수, 중위수, 제3사분위수, 최대값을 한번에 계산할 수 있다. | ||
|
||
```{r} | ||
tourism %>% | ||
janitor::clean_names() %>% | ||
features(trips, list(avg = mean, quantile)) | ||
``` | ||
|
||
## ACF | ||
|
||
자기 상관(Autocorrelation)을 앞서 1장에서 배웠다. | ||
|
||
### feat_acf | ||
자기 상관은 feat_acf를 이용하여 ACF에 관한 정보를 얻을 수 있다. | ||
|
||
* acf1: 시계열 데이터의 1차 자기상관계수 | ||
|
||
* acf10: 1~10차 자기상관계수 제곱합 | ||
|
||
* diff1_acf1: 1차 차분 시계열의 1차 자기상관계수 | ||
|
||
* diff1_acf10: 1차 차분 시계열의 1~10차 자기상관계수 제곱합 | ||
|
||
* diff2_acf1: 2차 차분 시계열의 1차 자기상관계수 | ||
|
||
* diff2_acf10: 2차 차분 시계열의 1~10차 자기상관계수 제곱합 | ||
|
||
* season_acf1: 첫번째 계절 시차에서의 자기상관계수 | ||
|
||
```{r} | ||
tourism %>% | ||
janitor::clean_names() %>% | ||
features(trips, feat_acf) | ||
``` | ||
tourism 데이터(분기별 호주 여행객수)는 분기별 데이터이기 때문에 위 결과에서 season_acf1은 시차 4에서의 자기상관계수값을 의미한다. | ||
|
||
## STL | ||
|
||
STL분해는 3장에서도 언급되었다. | ||
STL은 Seasonal and Trend decomposition using Loess의 줄임말로 robust한 시계열 분해 방법에 해당된다. | ||
|
||
시계열 분해는 추세요소$T_{t}$, 계절요소$S_{t}$, 관측치 $y_{t}$에서 추세요소와 계절 요소를 뺀 나머지 부분인 $R_{t}$로 나누어 볼 수 있었다. | ||
|
||
\[ | ||
y_{t}=T_{t}+S_{t}+R_{t} | ||
\] | ||
|
||
강한 추세를 가진 데이터의 경우, 계절 조덩된 데이터가 $R_{t}$보다 더 큰 변동을 가져야 한다. | ||
그러므로 $\frac{var(R_{t})}{var(T_{t}+R_{t})}$는 상대적으로 작아진다. | ||
추세의 강도는 아래와 같이 정의되며, 0과 1사이의 값을 가진다. | ||
|
||
\[ | ||
F_{t}=max(0,1-\frac{var(R_{t})}{var(T_{t}+R_{t})}) | ||
\] | ||
|
||
계절성의 강도는 아래와 같이 정의된다. | ||
|
||
\[ | ||
F_{s}=max(0,1-\frac{var(R_{t})}{var(S_{t}+R_{t})}) | ||
\] | ||
|
||
### feat_stl | ||
feat_stl을 이용하여 STL 분해 요소를 얻을 수 있다. | ||
추세와 계절성의 강도와 함께 아래와 같은 값들도 얻을 수 있다. | ||
|
||
* seasonal_peak_year: 계절성이 가장 큰 시점 | ||
|
||
* seasonal_trough_year: 계절성이 가장 작은 시점 | ||
|
||
* spikiness: $R_{t}$의 분산 | ||
|
||
* linearity: $T_{t}$(추세요소)의 선형성 | ||
|
||
* curvature: $T_{t}$(추세요소)의 곡률 | ||
|
||
* stl_e_acf1: 추세요소$T_{t}$와 계절요소$S_{t}$를 제외한 나머지 계열들의 1차 자기상관계수 | ||
|
||
* stl_e_acf10: 추세요소$T_{t}$와 계절요소$S_{t}$를 제외한 나머지 계열들의 1~10차 자기상관계수 제곱합 | ||
|
||
```{r} | ||
tourism %>% | ||
janitor::clean_names() %>% | ||
features(trips, feat_stl) | ||
``` | ||
|
||
위의 결과를 x축은 트렌드한 정도를, y축은 계절적인 정도를 표현해서 아래와 같이 시각화할 수 있다. | ||
```{r} | ||
tourism %>% | ||
janitor::clean_names() %>% | ||
features(trips, feat_stl) %>% | ||
ggplot(aes(x = trend_strength, y = seasonal_strength_year, | ||
col = purpose)) + | ||
geom_point() + | ||
facet_wrap(vars(state)) | ||
``` | ||
휴가를 목적으로 하는 관광이 계절성의 강도가 가장 큰 것을 보여준다. | ||
|
||
```{r} | ||
tourism %>% | ||
features(Trips, feat_stl) %>% | ||
filter(seasonal_strength_year == max(seasonal_strength_year)) %>% | ||
left_join(tourism, by = c("State", "Region", "Purpose")) %>% | ||
ggplot(aes(x = Quarter, y = Trips)) + | ||
geom_line() + | ||
facet_grid(vars(State, Region, Purpose)) | ||
``` | ||
|
||
|
This file contains 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
Binary file modified
BIN
-608 KB
(29%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-546 KB
(15%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-139 KB
(18%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-13-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-165 KB
(14%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-170 KB
(19%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-129 KB
(18%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-141 KB
(21%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-21-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-36.3 KB
(29%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-24-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-60.6 KB
(20%)
_bookdown_files/01-intro-to-tsibble_files/figure-html/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-608 KB
(29%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-64.9 KB
(20%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-66.5 KB
(22%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-849 KB
(19%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-4-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-54.8 KB
(25%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-661 KB
(14%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-5-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-32.6 KB
(33%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-849 KB
(19%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-661 KB
(14%)
...kdown_files/02-timeseries-decomposition_files/figure-html/unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-175 KB
(15%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-70.8 KB
(26%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-12-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-174 KB
(16%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-180 KB
(16%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-68 KB
(27%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-16-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-186 KB
(16%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-172 KB
(15%)
...own_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-18-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-207 KB
(13%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-2-1.png
Oops, something went wrong.
Binary file modified
BIN
-256 KB
(14%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-2-2.png
Oops, something went wrong.
Binary file modified
BIN
-61.6 KB
(24%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-2-3.png
Oops, something went wrong.
Binary file modified
BIN
-88.7 KB
(19%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-3-1.png
Oops, something went wrong.
Binary file modified
BIN
-90.2 KB
(17%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-4-1.png
Oops, something went wrong.
Binary file modified
BIN
-86.7 KB
(17%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-4-2.png
Oops, something went wrong.
Binary file modified
BIN
-175 KB
(15%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-5-1.png
Oops, something went wrong.
Binary file modified
BIN
-73.5 KB
(20%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-6-1.png
Oops, something went wrong.
Binary file modified
BIN
-87.1 KB
(21%)
...down_files/03-time-series-decomposition_files/figure-html/unnamed-chunk-6-2.png
Oops, something went wrong.
Binary file added
BIN
+35.4 KB
_bookdown_files/04-time-series-features_files/figure-html/unnamed-chunk-6-1.png
Oops, something went wrong.
Binary file added
BIN
+23.5 KB
_bookdown_files/04-time-series-features_files/figure-html/unnamed-chunk-7-1.png
Oops, something went wrong.
Binary file modified
BIN
-155 KB
(14%)
...kdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-16-1.png
Oops, something went wrong.
Binary file modified
BIN
-76.2 KB
(21%)
...kdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-20-1.png
Oops, something went wrong.
Binary file modified
BIN
-105 KB
(16%)
...kdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-21-1.png
Oops, something went wrong.
Binary file modified
BIN
-31.4 KB
(30%)
...kdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-22-1.png
Oops, something went wrong.
Binary file modified
BIN
-37.7 KB
(31%)
...kdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-23-1.png
Oops, something went wrong.
Binary file modified
BIN
-99.8 KB
(22%)
...kdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-24-1.png
Oops, something went wrong.
Binary file modified
BIN
-62.1 KB
(23%)
_bookdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-3-1.png
Oops, something went wrong.
Binary file modified
BIN
-60.6 KB
(26%)
_bookdown_files/05-the-forecasters-toolbox_files/figure-html/unnamed-chunk-7-1.png
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.