5. 비지도 학습 (Unsupervised Learning), Clustering 뜻, 파이썬 코드

2022. 2. 11. 21:11코딩/AI


* 비지도 학습 (Unsupervised Learning) 뜻

비지도 학습 (Unsupervised Learning)이란 데이터가 어떻게 구성되었는지 알아내는 기계 학습 문제를 뜻한다. 지도 학습 (Supervised Learning)과 달리 목표 Label이 주어지지 않는다.

 

 

 

 

 

 


* 클루스터링 (군집화, Clustering) 뜻

클루스터링 (군집화, Clustering)은 Data point들이 주어졌을 때, 그것을 몇개의 Cluster로 나누는 과정을 뜻한다. 

 

Supervised Learning인 Classification은 주어진 data를 label에 맞게 분류, 예측하는 것이다. Unsupervised Learning인 Clustering은 주어진 data들을 같은 성격에 맞게 묶는 것이다.

 

Classification 예시
Clustering 예시

 

 

 

 


* 계층적 클루스터링 (군집화, Hierarchical Clustering) 알고리즘

c = n, Ci = {xi}, i = 1, ... , n

While c>k
	Find the nearest pair of Ci & Cj
    Merge Ci & Cj
    c = c-1

반복적으로 두개의 가까운 클러스터를 찾아 합친다. 

 

 

 

 

 

 


* K-means Clustering Algorithm

- 초기 설정: x1, x2, ... ,xn => k clusters C1, C2, ... ,Ck로 설정(disjoint, exhaustive)

- Cluster center

- Objective funtion

- K-Means Clustering Algorithm

1. Make some k clusters
2. Calculate mean(center) of each cluster Ci_t
3. Find new cluster with center
4. Update clusters
5. Repeat

 

 

- K-Means Clustering의 한계

Hyperplane(nolinear boundary)을 기준으로 나눌 때, Center공식에 따라 원하는 대로 Clustering이 되지 않을 수 있다. -> Kernel Method로 해결할 수 있다.

 

 

 

 

 

 

 


* Kernel Method

Data를 original coordinate space에서 new space로 transform하면서 linear boundary로 사용할 수 있게한다. 

예시

하지만 이 transformation을 찾는 것은 매우 어렵다. 그래서 inner products를 이용한다.

 

Kernel Function의 종류는 Gaussian kernel, Polynomial Kernel이 있다.

 Gaussian kernel
Polynomial Kernel
kernel K-means 결과

이외에도 Weighted kernel K-means clustering, spectral clustering 등이 있다.

 

 

 


* K-means Clustering 파이썬 코드

 

K-means Clustering from Scratch in Python

In this article, we shall be covering the role of unsupervised learning algorithms, their applications, and K-means clustering approach. On…

medium.com