8 Unsupervised method

Download Report

Transcript 8 Unsupervised method

고급컴퓨터알고리듬
서울시립대학교 전기전자컴퓨터공학과
G201449015 이가희
8 Unsupervised method
Unsupervised
method
0. unsupervised method
•
•
클러스터 분석 : finds groups in your data with similar characteristics
•
계층 클러스터링
•
k-means
연관 분석 : finds elements or properties in the data that tend occur together
Unsupervised
method
1. cluster analysis
1.
Cluster analysis
•
목적 : 데이터내의 관측치들을 clustering을 통해 그룹화한다.
•
같은 클러스터 내에서는 유사도가 높아야 한다.
•
클러스터 분석
• hierarchical clustering
• k-means
Unsupervised
method
1.1 hierarchical clustering
1.
Cluster analysis
•
데이터에서 모든 두 클러스터간의 거리를 계산해 모든 데이터가 하나의 군집으로 병합될 때까
지의 클러스터들을 계층 구조로 만든다.
1.1
hierarchical
clustering
•
거리가 가장 가까운 것 2개를 묶음(반복), 하나의 클러스터로 합쳐질 때까지 진행한다.
•
dist(), hclust() 사용
•
dist(x, method, diag, upper)
• x : data(numeric matrix)
• method : 거리 측정 방법
• euclidean
• maximum
• manhattan
• binary
• minkowski
• diag : T/F
• upper : T/F
•
hclust(d, method)
• d : distance data
• method : 그룹 인접성 측정 방법
• ward.D, ward.D2
• single
• complete
• average
• median
• centroid
Unsupervised
method
1.
Cluster analysis
1.1
hierarchical
clustering
1.1 hierarchical clustering
Unsupervised
method
1.1 hierarchical clustering
1.
Cluster analysis
•
cutree() : 각 클러스터의 멤버들을 추출할 수 있다.
•
1.1
hierarchical
clustering
cutree(tree, k, h)
• tree : hcluter로 생성된 tree data
• k : 그룹 수
• h : 제한 높이
Unsupervised
method
1.1 hierarchical clustering
1.
Cluster analysis
•
visualizing cluters - 2차원 클러스터링
•
주성분분석(PCA)을 통해 2차원 plotting
•
prcomp() : 데이터의 주성분 계산, 많은 변수들로부터 몇 개의 주성분들을 추출한다.
1.1
hierarchical
clustering
•
prcomp(x)
• x : data
Unsupervised
method
1.
Cluster analysis
1.1
hierarchical
clustering
1.1 hierarchical clustering
Unsupervised
method
1.1 hierarchical clustering
1.
Cluster analysis
•
1.1
hierarchical
clustering
bootstrap evaluation of clusters : clusterboot()
•
•
library(fpc)
clusterboot(data, clustermethod)
• data : data matrix
• clustermethod : clustering method
• kmeansCBI(data, k) : kmeans clustering
• hclustCBI(data, k, method) : agglomerative hierarchical clustering
• …
Unsupervised
method
1.1 hierarchical clustering
1.
Cluster analysis
1.1
hierarchical
clustering
original cluster와 resampling cluster간의 자카드 유사도가 같거나 작을경우,
original cluster와 resampling cluster간의 자카드 유사도가 큰 경우,
Unsupervised
method
1.1 hierarchical clustering
1.
Cluster analysis
•
최적의 클러스터 수 산정 문제
•
Calinski-Harabasz index : 클러스터내 분산, 클러스터간 분산을 이용해 클러스터 개수를 선택한다.
1.1
hierarchical
clustering
•
•
•
클러스터내분산(W) = WSS(k) / (n-k)
클러스터간분산(B) = BSS(k) / (k-1)
ch = B / W, 최대값을 가지는 k를 클러스터 개수의 추정치로 선택한다.
•
good cluster : small WSS(k), large BSS(k)
•
WSS(total within sum of square) : 클러스터내 모든 점들의 평균점 - centroid로 정의
•
BSS(between sum of square) : TSS-WSS(k)
Unsupervised
method
1.
Cluster analysis
1.1
hierarchical
clustering
1.1 hierarchical clustering
Unsupervised
method
1.
Cluster analysis
1.1
hierarchical
clustering
1.1 hierarchical clustering
Unsupervised
method
1.2 k-means algorithm
1.
Cluster analysis
•
K개의 클러스터를 만들어 각 클러스터의 중심점을 기준으로 클러스터가 변화한다.
•
kmeans() 사용
1.2
k-means
algorithm
•
kmeans(x, centers, iter.max, nstart, algorithm, trace)
• x : data
• centers : 클러스터 개수 (k)
• iter.max : 반복 횟수
• nstart : 선택할 random sets 개수
• algorithm
• Hartigan-Wong
• Lloyd
• Forgy
• MacQueen
• trace : T/F
Unsupervised
method
1.2 k-means algorithm
1.
Cluster analysis
•
1.2
k-means
algorithm
bootstrap evaluation of clusters : clusterboot()
•
•
library(fpc)
clusterboot(data, clustermethod)
• data : data matrix
• clustermethod : clustering method
• kmeansCBI(data, k) : kmeans clustering
• hclustCBI(data, k, method) : agglomerative hierarchical clustering
• …
Unsupervised
method
1.
Cluster analysis
1.2
k-means
algorithm
1.2 k-means algorithm
•
최적의 클러스터 수 산정 문제 : kmeansruns()
•
kmeansruns(data, krange, criterion)
• data : data
• krange : 비교할 클러스터 범위
• criterion
• ch : Calinski-Harabasz Index
• asw : average silhouette width
•
•
•
a = 어떤 한 클러스터내의 점들의 평균거리
b = 다른 클러스터의 점들의 최소 평균거리
asw = 1-a/b, if a<b
Unsupervised
method
1.
Cluster analysis
1.2
k-means
algorithm
1.2 k-means algorithm
•
최적의 클러스터 수 산정 문제 : kmeansruns()
•
kmeansruns(data, krange, criterion)
• data : data
• krange : 비교할 클러스터 범위
• criterion
• ch : Calinski-Harabasz Index
• asw : average silhouette width
Unsupervised
method
1.2 k-means algorithm
1.
Cluster analysis
•
최적의 클러스터 수 산정 문제 : kmeansruns()
•
kmeansruns(data, krange, criterion)
• data : data
• krange : 비교할 클러스터 범위
• criterion
• ch : Calinski-Harabasz Index
• asw : average silhouette width
1.2
k-means
algorithm
Unsupervised
method
2. Association rules
2.
Association rules
•
Transaction – “togetherness”
•
트랜잭션간 연관성을 찾는 방법”
•
if X, then Y – conf(X=>Y) = support(union(X,Y) / support(X))
•
Support(X) = X / T
•
최소 10%의 지지도와 60%의 신뢰도를 갖는 연관 규칙을 찾는다.
Unsupervised
method
2.
Association
rules
2. Association rules
Unsupervised
method
2. Association rules
2.
Association rules
.
.
.
Unsupervised
method
2.
Association rules
2. Association rules
• apriori(data, parameter)
• data : data
• parameter
• support
• confidence
Unsupervised
method
2.
Association rules
2. Association rules
• inspect(x)
•
sort, sift 권장
• lift : lhs, rhs가 독립적인지 아닌지 판단하는 척도
Unsupervised
method
2.
Association rules
2. Association rules
• 제한조건
• apriori(data, parameter, appearance)
• data : data
• parameter
• support
• confidence
• appearance : 제한조건
Unsupervised
method
2.
Association rules
2. Association rules
• inspect(x)
cf)