<- data.frame(x1 = c(1:4),
or_dat x2 = c(5:8),
x3 = c(9:12))
<- data.frame(x1 = runif(4, min = 1, max = 4),
ref_dat x2 = runif(4, min = 5, max = 8),
x3 = runif(4, min = 9, max = 12))
gap statistic method
gap statistic method에 대해 알아보겠습니다. 알고리즘의 대략적인 순서는 다음과 같습니다.
에 대해 (군집 내 변동의 총합)를 계산
간단하게 그림처럼 각 군집별로 군집내 변동을 구하고, 전부 더해서
- reference data를 uniform distribution으로부터 생성하고
를 계산
우선 reference data를 어떻게 생성하는지 알아보겠습니다. reference data는 실제 데이터의 각 칼럼별 range(min ~ max) 값을 기준으로 uniform distribution을 통해 생성합니다(ex.unif(range(col1))). 이를
- Gap statistc 계산
- 아래 조건을 만족하는
선택
논문에서 추천하는 방법은 위의 수식처럼 reference data의 표준편차를 활용하여, 최적의
이렇게 하는 이유는 gap statistic이 변화율을 고려하여, 적절한
그림처럼 gap statistic이 구해진 경우 gap statistic이 가장 클 때를 기준으로 선택한다면 1-standard-error method
를 이용합니다.
논문 저자가 추천한 방법은 1-standard-error method
이지만 gap statistic을 구할 때 사용하는 cluster
패키지의 clueGap() 함수의 경우 다음과 같은 방법을 지원합니다.
globalmax : gap statistic의 maximum 값 선택
firstmax : gap statistic의 첫 번째 local maximum 값 선택
기타 등등
Example
library(tidyverse)
library(factoextra)
<- scale(USArrests)
df_6 %>% head() df_6
Murder Assault UrbanPop Rape
Alabama 1.24256408 0.7828393 -0.5209066 -0.003416473
Alaska 0.50786248 1.1068225 -1.2117642 2.484202941
Arizona 0.07163341 1.4788032 0.9989801 1.042878388
Arkansas 0.23234938 0.2308680 -1.0735927 -0.184916602
California 0.27826823 1.2628144 1.7589234 2.067820292
Colorado 0.02571456 0.3988593 0.8608085 1.864967207
set.seed(12)
fviz_nbclust(df_6, kmeans, method = "gap_stat")
fviz_nbclust()
의 경우 1-standard-error method
를 이용해서 계산됩니다. 그래프를 보면
시험에서는 근거만 제시하면 되기 때문에 그래프를 보고 1-standard-error method
로 표시된 점선을 최적의
Citation
@online{don2022,
author = {Don, Don and Don, Don},
title = {Gap Statistic},
date = {2022-10-08},
url = {https://dondonkim.netlify.app/posts/2022-10-07-gap-stat/gap_stat.html},
langid = {en}
}