SlideShare a Scribd company logo
1 of 36
Download to read offline
Unsupervised Learning
(+ regularization)
Sang Jun Lee
Ph.D. candidate, POSTECH
Email: lsj4u0208@postech.ac.kr
EECE695J 전자전기공학특론J(딥러닝기초및철강공정에의활용) – LECTURE 3 (2017. 9. 14)
2
▣ Lecture 2: supervised learning
▲ Machine learning : supervised learning, unsupervised learning, etc.
▲ Supervised learning: linear regression, logistic regression (classification), etc.
1-page Review
Supervised learning
Given a set of labeled example,
𝐷𝐷 = (𝑥𝑥𝑡𝑡, 𝑦𝑦𝑡𝑡) 𝑡𝑡=1
𝑁𝑁
, learn a mapping 𝑓𝑓: 𝑋𝑋 → 𝑌𝑌
which minimizes L(�𝑌𝑌 = 𝑓𝑓 𝑋𝑋 , 𝑌𝑌)
Unsupervised learning
Given a set of unlabeled example,
𝐷𝐷 = (𝑥𝑥𝑡𝑡) 𝑡𝑡=1
𝑁𝑁
, learn a meaningful
representation of the data
Linear regression
ℎ𝜽𝜽 𝒙𝒙 = ∑𝑖𝑖=0
𝑛𝑛
𝜃𝜃𝑖𝑖 𝑥𝑥𝑖𝑖 = 𝜽𝜽𝑇𝑇
𝒙𝒙
𝐽𝐽 𝜽𝜽 =
1
2
Σ𝑖𝑖=1
𝑚𝑚
ℎ𝜽𝜽 𝒙𝒙 𝒊𝒊
− 𝑦𝑦 𝑖𝑖 2
𝜃𝜃𝑗𝑗 ≔ 𝜃𝜃𝑗𝑗 − 𝛼𝛼 ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖
− 𝑦𝑦 𝑖𝑖
⋅ 𝑥𝑥𝑗𝑗
(𝑖𝑖)
ℎ𝜽𝜽 𝒙𝒙 =
1
1+𝑒𝑒−𝜽𝜽 𝑇𝑇 𝒙𝒙
ℎ𝜽𝜽 𝒙𝒙 ≥ 0.5 → 𝑦𝑦 = 1
ℎ𝜽𝜽 𝒙𝒙 < 0.5 → 𝑦𝑦 = 0
𝑙𝑙 𝜽𝜽 = ∑𝑖𝑖=1
𝑚𝑚
𝑦𝑦(𝑖𝑖)
log ℎ𝜽𝜽(𝒙𝒙 𝑖𝑖
) + (1 − 𝑦𝑦 𝑖𝑖
) log(1 − ℎ𝜽𝜽(𝒙𝒙 𝑖𝑖
))
𝜃𝜃𝑗𝑗 ≔ 𝜃𝜃𝑗𝑗 + 𝛼𝛼 𝑦𝑦 𝑖𝑖
− ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖
⋅ 𝑥𝑥𝑗𝑗
𝑖𝑖
Logistic regression
▣ Overfitting?
Training data에 지나치게(over) fit 되어 일반적인 추세를 표현하지 못하는 문제
일반적으로 학습데이터에 지나치게 편향된 복잡한 모델(불필요한 curve)로 인하여 발생
▣ Overfitting을 줄이기 위한 방법
▲ Reduce the number of parameters
(데이터를 표현하는 feature vector를 효과적으로 구성함으로써 data의 dimension 축소)
▲ Regularization (cost function)
3
The problem of overfitting
적절한 hypothesis function은
단순할 함수일 것이라는 가정
▣ Regularization
Parameter의 개수를 유지하되 크기를 감소시킴으로써 overfitting을 피하는 방법
Housing price prediction 문제에서의 hypothesis function:
ℎ𝜽𝜽 𝒙𝒙 = 𝜃𝜃0 + 𝜃𝜃1 𝑥𝑥1 + 𝜃𝜃2 𝑥𝑥2
모델에 따라 under-fitting (high bias) 또는 overfitting (high variance)의 문제가 발생할 수 있다!
4
The problem of overfitting
▣ Regularization
Linear regression에서의 cost function:
𝐽𝐽 𝜽𝜽 =
1
2𝑚𝑚
�
𝑖𝑖=1
𝑚𝑚
ℎ𝜽𝜽 𝒙𝒙 𝒊𝒊
− 𝑦𝑦 𝑖𝑖 2
위 식에서 parameter 𝜽𝜽 의 크기를 줄이는 regularization parameter 𝜆𝜆의 도입
Gradient descent에서 update rule:
5
The problem of overfitting
𝐽𝐽 𝜽𝜽 =
1
2𝑚𝑚
�
𝑖𝑖=1
𝑚𝑚
ℎ𝜽𝜽 𝒙𝒙 𝒊𝒊
− 𝑦𝑦 𝑖𝑖 2
+ 𝜆𝜆 ⋅ �
𝑗𝑗=1
𝑛𝑛
𝜃𝜃𝑗𝑗
2
𝜃𝜃0 ≔ 𝜃𝜃0 − 𝛼𝛼 ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖
− 𝑦𝑦 𝑖𝑖
⋅ 𝑥𝑥0
(𝑖𝑖)
𝜃𝜃𝑗𝑗 ≔ 𝜃𝜃𝑗𝑗 1 − 𝛼𝛼
𝜆𝜆
𝑚𝑚
− 𝛼𝛼
1
𝑚𝑚
�
𝑖𝑖=1
𝑚𝑚
ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖
− 𝑦𝑦 𝑖𝑖
⋅ 𝑥𝑥𝑗𝑗
𝑖𝑖
𝜃𝜃0은 regularize 하지 않음
Update 할 때 parameter의 크기를 감소시키는 효과!
▣ Normal equation의 변화
Linear regression에서의 normal equation :
, where 𝑋𝑋 =
−𝒙𝒙 𝟏𝟏 𝑇𝑇
−
⋮
−𝒙𝒙 𝒎𝒎 𝑇𝑇
−
, 𝜽𝜽 =
𝜃𝜃0
⋮
𝜃𝜃𝑛𝑛
, and 𝒚𝒚 =
𝑦𝑦(1)
⋮
𝑦𝑦(𝑚𝑚)
Regularization parameter를 도입하면
참고: 𝑋𝑋 𝑇𝑇
𝑋𝑋 + 𝜆𝜆 ⋅ 𝐼𝐼의 역행렬은 항상 존재 (𝜆𝜆 > 0)
6
Regularization
Positive semi-definiter (if 𝑚𝑚 ≤ 𝑛𝑛, 𝑋𝑋 𝑇𝑇
𝑋𝑋 is not invertiable)
Positive definite
▣ Validation set의 구성!
▲ 여러 복잡도의 모델을 구성하여 validation 성능을 관찰
ℎ𝜽𝜽 𝒙𝒙 = 𝜃𝜃0 + 𝜃𝜃1 𝑥𝑥1 + ⋯ + 𝜃𝜃𝑑𝑑 𝑥𝑥𝑑𝑑
▲ 적절한 크기의 regularization parameter (𝜆𝜆)를 정해주는 것이 중요!
(𝜆𝜆값이 너무 크면 under-fitting 되는 문제가 발생)
7
Bias vs. Variance
그림 출처: https://www.coursera.org/learn/machine-learning/resources/LIZza
8
▣ Clustering
비슷한 특성의 데이터들을 묶는 알고리즘
▲ K-means algorithm
▲ Spectral clustering
▣ Anomaly detection
▲ Density estimation
Unsupervised learning
EECE695J (2017)
Sang Jun Lee (POSTECH)
K-means
Cluster의 center로부터의
거리를 기준으로 clustering
Spectral clustering
𝐺𝐺(𝑉𝑉, 𝐸𝐸): vertices and edges
얼마나 적은 비용으로 그래
프를 partitioning 할 것인가
9
주어진 𝑁𝑁개의 데이터( 𝒙𝒙𝒕𝒕 ∈ ℝ𝐷𝐷
𝑡𝑡=1
𝑁𝑁
)를 대표하는 𝑘𝑘개의 center 𝝁𝝁𝒋𝒋 (𝑗𝑗 = 1, ⋯ , 𝐾𝐾)를 찾는 문제
→ 데이터들을 𝑘𝑘개의 그룹으로 partitioning
Initialize 𝝁𝝁𝒋𝒋 (𝑗𝑗 = 1, ⋯ , 𝐾𝐾)
Repeat until convergence!
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Assignment step
Assign all data points to the cluster for which 𝒙𝒙𝒕𝒕 − 𝝁𝝁𝒋𝒋
2
is smallest
Update step
Compute new means for every cluster
𝝁𝝁𝒋𝒋
𝒏𝒏𝒏𝒏𝒏𝒏
=
1
𝑁𝑁𝑗𝑗
Σ𝑡𝑡∈𝐶𝐶𝑗𝑗
𝒙𝒙𝒕𝒕
찾아야하는게 optimal cluster와 optimal mean인데..
mean을 고정하여 optimal cluster를 먼저 찾고
찾은 optimal cluster 안에서
새로운 optimal mean 계산
Not optimal solution!
10
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Initialize
11
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Initialize Assignment step
12
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Initialize Assignment step Update step
13
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Initialize Assignment step Update step
Assignment step
14
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Initialize Assignment step Update step
Assignment step Update step
15
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
Initialize Assignment step Update step
Assignment step Update step Assignment step
16
K-means algorithm in TensorFlow
EECE695J (2017)
Sang Jun Lee (POSTECH)
ipython의 웹상에서 그림을 그리기 위한 명령어
두 개의 normal distribution으로
sample data 구성
vectors_set : 2000x2
17
K-means algorithm in TensorFlow
EECE695J (2017)
Sang Jun Lee (POSTECH)
18
K-means algorithm in TensorFlow
EECE695J (2017)
Sang Jun Lee (POSTECH)
2000개의 샘플 중 k개를 임의로 선
택하여 initial mean 값으로 활용
expanded_vectors: (tensor) 1x2000x2
expanded_centroids: (tensor) 4x1x2
19
K-means algorithm in TensorFlow
EECE695J (2017)
Sang Jun Lee (POSTECH)
Assignment 과정도 값이 들어가는 것이 아니라
일종의 operation에 해당하는 graph
20
K-means algorithm in TensorFlow
EECE695J (2017)
Sang Jun Lee (POSTECH)
실제 학습과정 (100회 반복)
K=4 K=2
21
▣ K-means algorithm의 중요한 두 가지 이슈
▲ Mean의 initialization을 어떻게 할 것인가?
Random initialization:
• N개의 샘플 중 k개를 무작위로 뽑아 초기값으로 사용
• 초기값에 따라 clustering의 결과가 안좋을 수 있음
• Random initialization 과정을 여러 번 수행
▲ Cluster의 개수 k의 결정
일반적으로 cluster의 개수를 데이터의 분포에 따라 사람이 결정하는데..
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
그림 출처: https://wikidocs.net/4693
22
▣ K-means algorithm의 중요한 두 가지 이슈
▲ Cluster의 개수 k의 결정
Elbow method:
• k값에 따른 cost function에 대한 함수를 그렸을 때, 특정 k 이후 cost가 변화가 적은 elbow point를 k값으로 결정
• k값에 따른 cost function의 변화가 smooth 할 경우 elbow point를 찾기 힘들 수 있다.
K-means algorithm
EECE695J (2017)
Sang Jun Lee (POSTECH)
그림 출처: https://wikidocs.net/4693
23
▣ Clustering criteria:
▲ The affinities of data within the same cluster should be high
▲ The affinities of data between different clusters should be low
Spectral clustering
EECE695J (2017)
그림 참조: POSTECH CSED441 lecture13
데이터 샘플 사이의 관련성
24
Optimization objective:
Affinity의 총 합이 최대가 되는 cluster를 찾는 것이 목적 (𝒙𝒙 : 데이터의 cluster 정보를 나타내는 vector)
Convert the discrete optimization problem to continuous domain (+ 𝑥𝑥의 length로 normalize)
Spectral clustering
EECE695J (2017)
Discrete optimization problem
Maximum eigenvalue problem
25
Spectral clustering의 또 다른 이해
Minimum-cut algorithm
Spectral clustering
EECE695J (2017)
26
Minimum-cut algorithm
Gaussian similarity function
Spectral clustering
EECE695J (2017)
𝑤𝑤𝑖𝑖𝑖𝑖 = exp{−
𝑣𝑣𝑖𝑖 − 𝑣𝑣𝑗𝑗
2
2𝜎𝜎2
}
Diagonal = 1
Off-diagonal ≤ 1
Affinity matrix
𝑛𝑛
𝟐𝟐
×
𝑛𝑛
𝟐𝟐
matrix
27
Objective function:
Spectral clustering
EECE695J (2017)
Reference: POSTECH CSED441 lecture13
28
위의 최적화 문제는 결국 아래와 같은 eigenvalue problem으로 바뀌는데..
(Unnormalized) graph Laplacian:
• For every vector 𝒙𝒙 ∈ ℝ𝑛𝑛
, 𝒙𝒙𝑇𝑇
𝐿𝐿𝒙𝒙 =
1
2
∑𝑖𝑖=1
𝑛𝑛
∑𝑗𝑗=1
𝑛𝑛
𝑤𝑤𝑖𝑖𝑖𝑖 𝑥𝑥𝑖𝑖 − 𝑥𝑥𝑗𝑗
2
≥ 0 (positive semi-definite)
• 𝐿𝐿은 단 1개의 𝜆𝜆 = 0을 만족하는 eigenvalue를 가지며, 그 때의 eigenvector는 𝒙𝒙 = 𝟏𝟏 이다.
• 모든 데이터가 하나의 cluster로 묶이는 것은 의미가 없으므로..
Minimum-cut algorithm의 solution은 second minimum eigenvalue에 해당하는 eigenvector
Spectral clustering
EECE695J (2017)
𝐿𝐿 = 𝐷𝐷 − 𝑊𝑊
29
Minimum-cut algorithm:
• Find the second minimum eigenvector of 𝐿𝐿 = 𝐷𝐷 − 𝑊𝑊
• Partition the second minimum eigenvector
참고: Two moon data에서의 second minimum eigenvector
참고:
Minimum-cut algorithm은 optimal solution을 찾는 것이 아니라 optimal solution의 approximation을 찾는다
Spectral clustering
EECE695J (2017)
Second smallest eigenvector
30
K-means
• 알고리즘이 간단!
• 초기값에 따른 알고리즘 결과의 변동성
Spectral clustering
• 계산량이 많음
• 데이터의 cluster가 highly non-convex일 때 효과적!
• 동일 데이터에 대하여 비슷한 결과 도출
K-means vs. spectral clustering
EECE695J (2017)
Reference: POSTECH Machine Learning lecture8
K-means
Spectral
clustering
31
일반적인 데이터가 파란색과 같은 분포를 가질 때,
(빨간색 점들과 같이) 이상한 데이터들을 검출해내는 방법?
Anomaly detection
EECE695J (2017)
32
일반적인 데이터가 파란색과 같은 분포를 가질 때,
(빨간색 점들과 같이) 이상한 데이터들을 검출해내는 방법?
Density estimation using multivariate Gaussian distribution
Anomaly detection
EECE695J (2017)
33
Density estimation using multivariate Gaussian distribution
Parameter fitting:
Given training set {𝑥𝑥 𝑖𝑖
∈ ℝ𝑛𝑛
: 𝑖𝑖 = 1, ⋯ , 𝑚𝑚}
𝜇𝜇 =
1
𝑚𝑚
�
𝑖𝑖=1
𝑚𝑚
𝑥𝑥(𝑖𝑖)
Σ =
1
𝑚𝑚
�
𝑖𝑖=1
𝑚𝑚
𝑥𝑥 𝑖𝑖
− 𝜇𝜇 𝑥𝑥 𝑖𝑖
− 𝜇𝜇
𝑇𝑇
Anomaly if 𝑝𝑝 𝑥𝑥; 𝜇𝜇, Σ < 𝜖𝜖 for given 𝜖𝜖
Anomaly detection
EECE695J (2017)
34
Density estimation using multivariate Gaussian distribution
Anomaly detection
EECE695J (2017)
35
▲ Regularization for preventing overfitting
▲ Unsupervised learning
• Clustering: k-means, spectral clustering
• Anomaly detection (density estimation)
Summary
36
Date: 2017. 9. 21 (Thur)
Time: 14:00-15:15
▣ Introduction to neural networks
▲ Basic structure of neural networks: linear transformation, activation functions
▲ Implementation of neural network in Python and TensorFlow
Preview (Lecture 4)

More Related Content

What's hot

neural network 기초
neural network 기초neural network 기초
neural network 기초Dea-hwan Ki
 
Focal loss의 응용(Detection & Classification)
Focal loss의 응용(Detection & Classification)Focal loss의 응용(Detection & Classification)
Focal loss의 응용(Detection & Classification)홍배 김
 
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...홍배 김
 
Anomaly Detection with GANs
Anomaly Detection with GANsAnomaly Detection with GANs
Anomaly Detection with GANs홍배 김
 
Vs^3 net for machine reading comprehension question answering
Vs^3 net for machine reading comprehension question answeringVs^3 net for machine reading comprehension question answering
Vs^3 net for machine reading comprehension question answeringNAVER Engineering
 
알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder홍배 김
 
A neural image caption generator
A neural image caption generatorA neural image caption generator
A neural image caption generator홍배 김
 
Rnn개념정리
Rnn개념정리Rnn개념정리
Rnn개념정리종현 최
 
Deep Learning & Convolutional Neural Network
Deep Learning & Convolutional Neural NetworkDeep Learning & Convolutional Neural Network
Deep Learning & Convolutional Neural Networkagdatalab
 
Attention is all you need 설명
Attention is all you need 설명Attention is all you need 설명
Attention is all you need 설명Junho Lee
 
[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropoutWuhyun Rico Shin
 
Deep learning seminar_snu_161031
Deep learning seminar_snu_161031Deep learning seminar_snu_161031
Deep learning seminar_snu_161031Jinwon Lee
 
Q Learning과 CNN을 이용한 Object Localization
Q Learning과 CNN을 이용한 Object LocalizationQ Learning과 CNN을 이용한 Object Localization
Q Learning과 CNN을 이용한 Object Localization홍배 김
 
Graph Neural Network (한국어)
Graph Neural Network (한국어)Graph Neural Network (한국어)
Graph Neural Network (한국어)Jungwon Kim
 
Learning to remember rare events
Learning to remember rare eventsLearning to remember rare events
Learning to remember rare events홍배 김
 
Murpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical ModelMurpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical ModelJungkyu Lee
 
7. Linear Regression
7. Linear Regression7. Linear Regression
7. Linear RegressionJungkyu Lee
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic RegressionJungkyu Lee
 
RUCK 2017 빅데이터 분석에서 모형의 역할
RUCK 2017 빅데이터 분석에서 모형의 역할RUCK 2017 빅데이터 분석에서 모형의 역할
RUCK 2017 빅데이터 분석에서 모형의 역할r-kor
 
머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian ProcessesJungkyu Lee
 

What's hot (20)

neural network 기초
neural network 기초neural network 기초
neural network 기초
 
Focal loss의 응용(Detection & Classification)
Focal loss의 응용(Detection & Classification)Focal loss의 응용(Detection & Classification)
Focal loss의 응용(Detection & Classification)
 
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
 
Anomaly Detection with GANs
Anomaly Detection with GANsAnomaly Detection with GANs
Anomaly Detection with GANs
 
Vs^3 net for machine reading comprehension question answering
Vs^3 net for machine reading comprehension question answeringVs^3 net for machine reading comprehension question answering
Vs^3 net for machine reading comprehension question answering
 
알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder
 
A neural image caption generator
A neural image caption generatorA neural image caption generator
A neural image caption generator
 
Rnn개념정리
Rnn개념정리Rnn개념정리
Rnn개념정리
 
Deep Learning & Convolutional Neural Network
Deep Learning & Convolutional Neural NetworkDeep Learning & Convolutional Neural Network
Deep Learning & Convolutional Neural Network
 
Attention is all you need 설명
Attention is all you need 설명Attention is all you need 설명
Attention is all you need 설명
 
[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout
 
Deep learning seminar_snu_161031
Deep learning seminar_snu_161031Deep learning seminar_snu_161031
Deep learning seminar_snu_161031
 
Q Learning과 CNN을 이용한 Object Localization
Q Learning과 CNN을 이용한 Object LocalizationQ Learning과 CNN을 이용한 Object Localization
Q Learning과 CNN을 이용한 Object Localization
 
Graph Neural Network (한국어)
Graph Neural Network (한국어)Graph Neural Network (한국어)
Graph Neural Network (한국어)
 
Learning to remember rare events
Learning to remember rare eventsLearning to remember rare events
Learning to remember rare events
 
Murpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical ModelMurpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical Model
 
7. Linear Regression
7. Linear Regression7. Linear Regression
7. Linear Regression
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic Regression
 
RUCK 2017 빅데이터 분석에서 모형의 역할
RUCK 2017 빅데이터 분석에서 모형의 역할RUCK 2017 빅데이터 분석에서 모형의 역할
RUCK 2017 빅데이터 분석에서 모형의 역할
 
머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes
 

Similar to Lecture 3: Unsupervised Learning

Deep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learningDeep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learningJinSooKim80
 
Guided policy search
Guided policy searchGuided policy search
Guided policy searchJaehyeon Park
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리SANG WON PARK
 
Neural network (perceptron)
Neural network (perceptron)Neural network (perceptron)
Neural network (perceptron)Jeonghun Yoon
 
Deep Learning from scratch 5장 : backpropagation
 Deep Learning from scratch 5장 : backpropagation Deep Learning from scratch 5장 : backpropagation
Deep Learning from scratch 5장 : backpropagationJinSooKim80
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트
[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트
[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트S.O.P.T - Shout Our Passion Together
 
Eigendecomposition and pca
Eigendecomposition and pcaEigendecomposition and pca
Eigendecomposition and pcaJinhwan Suk
 
Control as Inference.pptx
Control as Inference.pptxControl as Inference.pptx
Control as Inference.pptxssuserbd1647
 
Gaussian Mixture Model
Gaussian Mixture ModelGaussian Mixture Model
Gaussian Mixture ModelKyeongUkJang
 
Multinomial classification and application of ML
Multinomial classification and application of MLMultinomial classification and application of ML
Multinomial classification and application of ML희수 박
 
가깝고도 먼 Trpo
가깝고도 먼 Trpo가깝고도 먼 Trpo
가깝고도 먼 TrpoWoong won Lee
 
Auto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-EncodersAuto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-EncodersJinho Lee
 
RLCode와 A3C 쉽고 깊게 이해하기
RLCode와 A3C 쉽고 깊게 이해하기RLCode와 A3C 쉽고 깊게 이해하기
RLCode와 A3C 쉽고 깊게 이해하기Woong won Lee
 
파이썬과 케라스로 배우는 강화학습 저자특강
파이썬과 케라스로 배우는 강화학습 저자특강파이썬과 케라스로 배우는 강화학습 저자특강
파이썬과 케라스로 배우는 강화학습 저자특강Woong won Lee
 
[Probability for machine learning]
[Probability for machine learning][Probability for machine learning]
[Probability for machine learning]강민국 강민국
 
3.neural networks
3.neural networks3.neural networks
3.neural networksHaesun Park
 
08. spectal clustering
08. spectal clustering08. spectal clustering
08. spectal clusteringJeonghun Yoon
 
한국인공지능연구소 강화학습랩 결과보고서
한국인공지능연구소 강화학습랩 결과보고서한국인공지능연구소 강화학습랩 결과보고서
한국인공지능연구소 강화학습랩 결과보고서Euijin Jeong
 

Similar to Lecture 3: Unsupervised Learning (20)

Deep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learningDeep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learning
 
Guided policy search
Guided policy searchGuided policy search
Guided policy search
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리
 
Neural network (perceptron)
Neural network (perceptron)Neural network (perceptron)
Neural network (perceptron)
 
Deep Learning from scratch 5장 : backpropagation
 Deep Learning from scratch 5장 : backpropagation Deep Learning from scratch 5장 : backpropagation
Deep Learning from scratch 5장 : backpropagation
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트
[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트
[SOPT] 데이터 구조 및 알고리즘 스터디 - #01 : 개요, 점근적 복잡도, 배열, 연결리스트
 
Eigendecomposition and pca
Eigendecomposition and pcaEigendecomposition and pca
Eigendecomposition and pca
 
2016 UCPC 풀이
2016 UCPC 풀이2016 UCPC 풀이
2016 UCPC 풀이
 
Control as Inference.pptx
Control as Inference.pptxControl as Inference.pptx
Control as Inference.pptx
 
Gaussian Mixture Model
Gaussian Mixture ModelGaussian Mixture Model
Gaussian Mixture Model
 
Multinomial classification and application of ML
Multinomial classification and application of MLMultinomial classification and application of ML
Multinomial classification and application of ML
 
가깝고도 먼 Trpo
가깝고도 먼 Trpo가깝고도 먼 Trpo
가깝고도 먼 Trpo
 
Auto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-EncodersAuto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-Encoders
 
RLCode와 A3C 쉽고 깊게 이해하기
RLCode와 A3C 쉽고 깊게 이해하기RLCode와 A3C 쉽고 깊게 이해하기
RLCode와 A3C 쉽고 깊게 이해하기
 
파이썬과 케라스로 배우는 강화학습 저자특강
파이썬과 케라스로 배우는 강화학습 저자특강파이썬과 케라스로 배우는 강화학습 저자특강
파이썬과 케라스로 배우는 강화학습 저자특강
 
[Probability for machine learning]
[Probability for machine learning][Probability for machine learning]
[Probability for machine learning]
 
07. PCA
07. PCA07. PCA
07. PCA
 
3.neural networks
3.neural networks3.neural networks
3.neural networks
 
08. spectal clustering
08. spectal clustering08. spectal clustering
08. spectal clustering
 
한국인공지능연구소 강화학습랩 결과보고서
한국인공지능연구소 강화학습랩 결과보고서한국인공지능연구소 강화학습랩 결과보고서
한국인공지능연구소 강화학습랩 결과보고서
 

Lecture 3: Unsupervised Learning

  • 1. Unsupervised Learning (+ regularization) Sang Jun Lee Ph.D. candidate, POSTECH Email: lsj4u0208@postech.ac.kr EECE695J 전자전기공학특론J(딥러닝기초및철강공정에의활용) – LECTURE 3 (2017. 9. 14)
  • 2. 2 ▣ Lecture 2: supervised learning ▲ Machine learning : supervised learning, unsupervised learning, etc. ▲ Supervised learning: linear regression, logistic regression (classification), etc. 1-page Review Supervised learning Given a set of labeled example, 𝐷𝐷 = (𝑥𝑥𝑡𝑡, 𝑦𝑦𝑡𝑡) 𝑡𝑡=1 𝑁𝑁 , learn a mapping 𝑓𝑓: 𝑋𝑋 → 𝑌𝑌 which minimizes L(�𝑌𝑌 = 𝑓𝑓 𝑋𝑋 , 𝑌𝑌) Unsupervised learning Given a set of unlabeled example, 𝐷𝐷 = (𝑥𝑥𝑡𝑡) 𝑡𝑡=1 𝑁𝑁 , learn a meaningful representation of the data Linear regression ℎ𝜽𝜽 𝒙𝒙 = ∑𝑖𝑖=0 𝑛𝑛 𝜃𝜃𝑖𝑖 𝑥𝑥𝑖𝑖 = 𝜽𝜽𝑇𝑇 𝒙𝒙 𝐽𝐽 𝜽𝜽 = 1 2 Σ𝑖𝑖=1 𝑚𝑚 ℎ𝜽𝜽 𝒙𝒙 𝒊𝒊 − 𝑦𝑦 𝑖𝑖 2 𝜃𝜃𝑗𝑗 ≔ 𝜃𝜃𝑗𝑗 − 𝛼𝛼 ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖 − 𝑦𝑦 𝑖𝑖 ⋅ 𝑥𝑥𝑗𝑗 (𝑖𝑖) ℎ𝜽𝜽 𝒙𝒙 = 1 1+𝑒𝑒−𝜽𝜽 𝑇𝑇 𝒙𝒙 ℎ𝜽𝜽 𝒙𝒙 ≥ 0.5 → 𝑦𝑦 = 1 ℎ𝜽𝜽 𝒙𝒙 < 0.5 → 𝑦𝑦 = 0 𝑙𝑙 𝜽𝜽 = ∑𝑖𝑖=1 𝑚𝑚 𝑦𝑦(𝑖𝑖) log ℎ𝜽𝜽(𝒙𝒙 𝑖𝑖 ) + (1 − 𝑦𝑦 𝑖𝑖 ) log(1 − ℎ𝜽𝜽(𝒙𝒙 𝑖𝑖 )) 𝜃𝜃𝑗𝑗 ≔ 𝜃𝜃𝑗𝑗 + 𝛼𝛼 𝑦𝑦 𝑖𝑖 − ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖 ⋅ 𝑥𝑥𝑗𝑗 𝑖𝑖 Logistic regression
  • 3. ▣ Overfitting? Training data에 지나치게(over) fit 되어 일반적인 추세를 표현하지 못하는 문제 일반적으로 학습데이터에 지나치게 편향된 복잡한 모델(불필요한 curve)로 인하여 발생 ▣ Overfitting을 줄이기 위한 방법 ▲ Reduce the number of parameters (데이터를 표현하는 feature vector를 효과적으로 구성함으로써 data의 dimension 축소) ▲ Regularization (cost function) 3 The problem of overfitting 적절한 hypothesis function은 단순할 함수일 것이라는 가정
  • 4. ▣ Regularization Parameter의 개수를 유지하되 크기를 감소시킴으로써 overfitting을 피하는 방법 Housing price prediction 문제에서의 hypothesis function: ℎ𝜽𝜽 𝒙𝒙 = 𝜃𝜃0 + 𝜃𝜃1 𝑥𝑥1 + 𝜃𝜃2 𝑥𝑥2 모델에 따라 under-fitting (high bias) 또는 overfitting (high variance)의 문제가 발생할 수 있다! 4 The problem of overfitting
  • 5. ▣ Regularization Linear regression에서의 cost function: 𝐽𝐽 𝜽𝜽 = 1 2𝑚𝑚 � 𝑖𝑖=1 𝑚𝑚 ℎ𝜽𝜽 𝒙𝒙 𝒊𝒊 − 𝑦𝑦 𝑖𝑖 2 위 식에서 parameter 𝜽𝜽 의 크기를 줄이는 regularization parameter 𝜆𝜆의 도입 Gradient descent에서 update rule: 5 The problem of overfitting 𝐽𝐽 𝜽𝜽 = 1 2𝑚𝑚 � 𝑖𝑖=1 𝑚𝑚 ℎ𝜽𝜽 𝒙𝒙 𝒊𝒊 − 𝑦𝑦 𝑖𝑖 2 + 𝜆𝜆 ⋅ � 𝑗𝑗=1 𝑛𝑛 𝜃𝜃𝑗𝑗 2 𝜃𝜃0 ≔ 𝜃𝜃0 − 𝛼𝛼 ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖 − 𝑦𝑦 𝑖𝑖 ⋅ 𝑥𝑥0 (𝑖𝑖) 𝜃𝜃𝑗𝑗 ≔ 𝜃𝜃𝑗𝑗 1 − 𝛼𝛼 𝜆𝜆 𝑚𝑚 − 𝛼𝛼 1 𝑚𝑚 � 𝑖𝑖=1 𝑚𝑚 ℎ𝜽𝜽 𝒙𝒙 𝑖𝑖 − 𝑦𝑦 𝑖𝑖 ⋅ 𝑥𝑥𝑗𝑗 𝑖𝑖 𝜃𝜃0은 regularize 하지 않음 Update 할 때 parameter의 크기를 감소시키는 효과!
  • 6. ▣ Normal equation의 변화 Linear regression에서의 normal equation : , where 𝑋𝑋 = −𝒙𝒙 𝟏𝟏 𝑇𝑇 − ⋮ −𝒙𝒙 𝒎𝒎 𝑇𝑇 − , 𝜽𝜽 = 𝜃𝜃0 ⋮ 𝜃𝜃𝑛𝑛 , and 𝒚𝒚 = 𝑦𝑦(1) ⋮ 𝑦𝑦(𝑚𝑚) Regularization parameter를 도입하면 참고: 𝑋𝑋 𝑇𝑇 𝑋𝑋 + 𝜆𝜆 ⋅ 𝐼𝐼의 역행렬은 항상 존재 (𝜆𝜆 > 0) 6 Regularization Positive semi-definiter (if 𝑚𝑚 ≤ 𝑛𝑛, 𝑋𝑋 𝑇𝑇 𝑋𝑋 is not invertiable) Positive definite
  • 7. ▣ Validation set의 구성! ▲ 여러 복잡도의 모델을 구성하여 validation 성능을 관찰 ℎ𝜽𝜽 𝒙𝒙 = 𝜃𝜃0 + 𝜃𝜃1 𝑥𝑥1 + ⋯ + 𝜃𝜃𝑑𝑑 𝑥𝑥𝑑𝑑 ▲ 적절한 크기의 regularization parameter (𝜆𝜆)를 정해주는 것이 중요! (𝜆𝜆값이 너무 크면 under-fitting 되는 문제가 발생) 7 Bias vs. Variance 그림 출처: https://www.coursera.org/learn/machine-learning/resources/LIZza
  • 8. 8 ▣ Clustering 비슷한 특성의 데이터들을 묶는 알고리즘 ▲ K-means algorithm ▲ Spectral clustering ▣ Anomaly detection ▲ Density estimation Unsupervised learning EECE695J (2017) Sang Jun Lee (POSTECH) K-means Cluster의 center로부터의 거리를 기준으로 clustering Spectral clustering 𝐺𝐺(𝑉𝑉, 𝐸𝐸): vertices and edges 얼마나 적은 비용으로 그래 프를 partitioning 할 것인가
  • 9. 9 주어진 𝑁𝑁개의 데이터( 𝒙𝒙𝒕𝒕 ∈ ℝ𝐷𝐷 𝑡𝑡=1 𝑁𝑁 )를 대표하는 𝑘𝑘개의 center 𝝁𝝁𝒋𝒋 (𝑗𝑗 = 1, ⋯ , 𝐾𝐾)를 찾는 문제 → 데이터들을 𝑘𝑘개의 그룹으로 partitioning Initialize 𝝁𝝁𝒋𝒋 (𝑗𝑗 = 1, ⋯ , 𝐾𝐾) Repeat until convergence! K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Assignment step Assign all data points to the cluster for which 𝒙𝒙𝒕𝒕 − 𝝁𝝁𝒋𝒋 2 is smallest Update step Compute new means for every cluster 𝝁𝝁𝒋𝒋 𝒏𝒏𝒏𝒏𝒏𝒏 = 1 𝑁𝑁𝑗𝑗 Σ𝑡𝑡∈𝐶𝐶𝑗𝑗 𝒙𝒙𝒕𝒕 찾아야하는게 optimal cluster와 optimal mean인데.. mean을 고정하여 optimal cluster를 먼저 찾고 찾은 optimal cluster 안에서 새로운 optimal mean 계산 Not optimal solution!
  • 10. 10 K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Initialize
  • 11. 11 K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Initialize Assignment step
  • 12. 12 K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Initialize Assignment step Update step
  • 13. 13 K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Initialize Assignment step Update step Assignment step
  • 14. 14 K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Initialize Assignment step Update step Assignment step Update step
  • 15. 15 K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) Initialize Assignment step Update step Assignment step Update step Assignment step
  • 16. 16 K-means algorithm in TensorFlow EECE695J (2017) Sang Jun Lee (POSTECH) ipython의 웹상에서 그림을 그리기 위한 명령어 두 개의 normal distribution으로 sample data 구성 vectors_set : 2000x2
  • 17. 17 K-means algorithm in TensorFlow EECE695J (2017) Sang Jun Lee (POSTECH)
  • 18. 18 K-means algorithm in TensorFlow EECE695J (2017) Sang Jun Lee (POSTECH) 2000개의 샘플 중 k개를 임의로 선 택하여 initial mean 값으로 활용 expanded_vectors: (tensor) 1x2000x2 expanded_centroids: (tensor) 4x1x2
  • 19. 19 K-means algorithm in TensorFlow EECE695J (2017) Sang Jun Lee (POSTECH) Assignment 과정도 값이 들어가는 것이 아니라 일종의 operation에 해당하는 graph
  • 20. 20 K-means algorithm in TensorFlow EECE695J (2017) Sang Jun Lee (POSTECH) 실제 학습과정 (100회 반복) K=4 K=2
  • 21. 21 ▣ K-means algorithm의 중요한 두 가지 이슈 ▲ Mean의 initialization을 어떻게 할 것인가? Random initialization: • N개의 샘플 중 k개를 무작위로 뽑아 초기값으로 사용 • 초기값에 따라 clustering의 결과가 안좋을 수 있음 • Random initialization 과정을 여러 번 수행 ▲ Cluster의 개수 k의 결정 일반적으로 cluster의 개수를 데이터의 분포에 따라 사람이 결정하는데.. K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) 그림 출처: https://wikidocs.net/4693
  • 22. 22 ▣ K-means algorithm의 중요한 두 가지 이슈 ▲ Cluster의 개수 k의 결정 Elbow method: • k값에 따른 cost function에 대한 함수를 그렸을 때, 특정 k 이후 cost가 변화가 적은 elbow point를 k값으로 결정 • k값에 따른 cost function의 변화가 smooth 할 경우 elbow point를 찾기 힘들 수 있다. K-means algorithm EECE695J (2017) Sang Jun Lee (POSTECH) 그림 출처: https://wikidocs.net/4693
  • 23. 23 ▣ Clustering criteria: ▲ The affinities of data within the same cluster should be high ▲ The affinities of data between different clusters should be low Spectral clustering EECE695J (2017) 그림 참조: POSTECH CSED441 lecture13 데이터 샘플 사이의 관련성
  • 24. 24 Optimization objective: Affinity의 총 합이 최대가 되는 cluster를 찾는 것이 목적 (𝒙𝒙 : 데이터의 cluster 정보를 나타내는 vector) Convert the discrete optimization problem to continuous domain (+ 𝑥𝑥의 length로 normalize) Spectral clustering EECE695J (2017) Discrete optimization problem Maximum eigenvalue problem
  • 25. 25 Spectral clustering의 또 다른 이해 Minimum-cut algorithm Spectral clustering EECE695J (2017)
  • 26. 26 Minimum-cut algorithm Gaussian similarity function Spectral clustering EECE695J (2017) 𝑤𝑤𝑖𝑖𝑖𝑖 = exp{− 𝑣𝑣𝑖𝑖 − 𝑣𝑣𝑗𝑗 2 2𝜎𝜎2 } Diagonal = 1 Off-diagonal ≤ 1 Affinity matrix 𝑛𝑛 𝟐𝟐 × 𝑛𝑛 𝟐𝟐 matrix
  • 27. 27 Objective function: Spectral clustering EECE695J (2017) Reference: POSTECH CSED441 lecture13
  • 28. 28 위의 최적화 문제는 결국 아래와 같은 eigenvalue problem으로 바뀌는데.. (Unnormalized) graph Laplacian: • For every vector 𝒙𝒙 ∈ ℝ𝑛𝑛 , 𝒙𝒙𝑇𝑇 𝐿𝐿𝒙𝒙 = 1 2 ∑𝑖𝑖=1 𝑛𝑛 ∑𝑗𝑗=1 𝑛𝑛 𝑤𝑤𝑖𝑖𝑖𝑖 𝑥𝑥𝑖𝑖 − 𝑥𝑥𝑗𝑗 2 ≥ 0 (positive semi-definite) • 𝐿𝐿은 단 1개의 𝜆𝜆 = 0을 만족하는 eigenvalue를 가지며, 그 때의 eigenvector는 𝒙𝒙 = 𝟏𝟏 이다. • 모든 데이터가 하나의 cluster로 묶이는 것은 의미가 없으므로.. Minimum-cut algorithm의 solution은 second minimum eigenvalue에 해당하는 eigenvector Spectral clustering EECE695J (2017) 𝐿𝐿 = 𝐷𝐷 − 𝑊𝑊
  • 29. 29 Minimum-cut algorithm: • Find the second minimum eigenvector of 𝐿𝐿 = 𝐷𝐷 − 𝑊𝑊 • Partition the second minimum eigenvector 참고: Two moon data에서의 second minimum eigenvector 참고: Minimum-cut algorithm은 optimal solution을 찾는 것이 아니라 optimal solution의 approximation을 찾는다 Spectral clustering EECE695J (2017) Second smallest eigenvector
  • 30. 30 K-means • 알고리즘이 간단! • 초기값에 따른 알고리즘 결과의 변동성 Spectral clustering • 계산량이 많음 • 데이터의 cluster가 highly non-convex일 때 효과적! • 동일 데이터에 대하여 비슷한 결과 도출 K-means vs. spectral clustering EECE695J (2017) Reference: POSTECH Machine Learning lecture8 K-means Spectral clustering
  • 31. 31 일반적인 데이터가 파란색과 같은 분포를 가질 때, (빨간색 점들과 같이) 이상한 데이터들을 검출해내는 방법? Anomaly detection EECE695J (2017)
  • 32. 32 일반적인 데이터가 파란색과 같은 분포를 가질 때, (빨간색 점들과 같이) 이상한 데이터들을 검출해내는 방법? Density estimation using multivariate Gaussian distribution Anomaly detection EECE695J (2017)
  • 33. 33 Density estimation using multivariate Gaussian distribution Parameter fitting: Given training set {𝑥𝑥 𝑖𝑖 ∈ ℝ𝑛𝑛 : 𝑖𝑖 = 1, ⋯ , 𝑚𝑚} 𝜇𝜇 = 1 𝑚𝑚 � 𝑖𝑖=1 𝑚𝑚 𝑥𝑥(𝑖𝑖) Σ = 1 𝑚𝑚 � 𝑖𝑖=1 𝑚𝑚 𝑥𝑥 𝑖𝑖 − 𝜇𝜇 𝑥𝑥 𝑖𝑖 − 𝜇𝜇 𝑇𝑇 Anomaly if 𝑝𝑝 𝑥𝑥; 𝜇𝜇, Σ < 𝜖𝜖 for given 𝜖𝜖 Anomaly detection EECE695J (2017)
  • 34. 34 Density estimation using multivariate Gaussian distribution Anomaly detection EECE695J (2017)
  • 35. 35 ▲ Regularization for preventing overfitting ▲ Unsupervised learning • Clustering: k-means, spectral clustering • Anomaly detection (density estimation) Summary
  • 36. 36 Date: 2017. 9. 21 (Thur) Time: 14:00-15:15 ▣ Introduction to neural networks ▲ Basic structure of neural networks: linear transformation, activation functions ▲ Implementation of neural network in Python and TensorFlow Preview (Lecture 4)