본문 바로가기

데이터 과학/데이터 과학

Density Estimation (in Python)

scikit-learn.org/stable/modules/density.html

 

2.8. Density Estimation — scikit-learn 0.24.1 documentation

2.8. Density Estimation Density estimation walks the line between unsupervised learning, feature engineering, and data modeling. Some of the most popular and useful density estimation techniques are mixture models such as Gaussian Mixtures (GaussianMixture

scikit-learn.org

아래 글은 본 링크 글을 번역한 것입니다.


Density estimation walks the line between unsupervised learning, feature engineering, and data modeling. Some of the most popular and useful density estimation techniques are mixture models such as Gaussian Mixtures (GaussianMixture), and neighbor-based approaches such as the kernel density estimate (KernelDensity). Gaussian Mixtures are discussed more fully in the context of clustering, because the technique is also useful as an unsupervised clustering scheme.

--> 밀도 추정은 비지도 학습, 특성 공학, 데이터 모델링 경계에 걸쳐 있다. 가장 인기 있는 밀도 추정은 가우시안 혼합모델(GMM), 커널 밀도 추정(kernel density estimate)과 같은 '인접 기반(neighbor-based)' 접근 방식이다.  GMM은 '비지도 클러스터링 전략'으로 유용하기에 클러스터링 방법으로도 논의 된다. 

 

 

※ 밀도 추정의 가장 간단한 예로 히스토그램 정규화가 있지만, Bins 수에 따라 결과 양상이 많이 다른 단점이 있다. 즉, 해석이 달라질 수 있다.

 

 

Kernel density estimation in scikit-learn is implemented in the KernelDensity estimator, which uses the Ball Tree or KD Tree for efficient queries (see Nearest Neighbors for a discussion of these). Though the above example uses a 1D data set for simplicity, kernel density estimation can be performed in any number of dimensions, though in practice the curse of dimensionality causes its performance to degrade in high dimensions.

--> 커널 밀도 추정은 (sklearn.neighbors.KernelDensity)에 구현되어 있다. Ball Tree 혹은 KD Tree를 이용한다. 

커널 밀도 추정은 어떠한 데이터 차원에서도 동작 가능하지만, 실험적으로 차원의 저주에 의해 고 차원에서는 성능이 떨어진다.

 

from sklearn.neighbors import KernelDensity
import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
kde = KernelDensity(kernel='gaussian', bandwidth=0.2).fit(X)
>>> kde.score_samples(X)
array([-0.41075698, -0.41075698, -0.41076071, -0.41075698, -0.41075698, -0.41076071])

 

 

Q. 어째서 X가 2차원 입력을 받는지??

 

Mathematically, a kernel is a positive function K(x;h) which is controlled by the bandwidth parameter h. Given this kernel form, the density estimate at a point y within a group of points xi;i=1⋯N is given by:

--> 수학적으로 커널은 양의 함수 K(x; h) 이며 Bandwitdh 파라미터 h에 의해 조정된다. 

 

해당 커널 형태에서 포인트 y의 밀도 추정은 다음과 같다.  $ x_i; i=1\cdots N $

 

$$ \rho_K(y) = \sum_{i=1}^{N} K(y - x_i; h) $$

 

대역폭은 편향과 분산 간의 균형을 제어하는 스무딩 파라미터 역할을 한다.

 

커널의 종류

One other useful application of kernel density estimation is to learn a non-parametric generative model of a dataset in order to efficiently draw new samples from this generative model. Here is an example of using this process to create a new set of hand-written digits, using a Gaussian kernel learned on a PCA projection of the data:

--> 커널 밀도 추정의 다른 유용한 응용으로는 비모수적 생성 모델을 학습하는 것이다. 생성모델에서 새로운 셈플을 생성 가능하다(데이터로 부터 생성한 밀도 함수를 생성 모델로 사용하는 듯 하다)

아래는 데이터의 PCA 프로젝션에서 학습한(??) 가우시안 커널을 사용하여 새로운 숫자 셈플을 생성하는 예이다.

 

 

학습한 가우시안 커널로 생성한 숫자

The “new” data consists of linear combinations of the input data, with weights probabilistically drawn given the KDE model.

-->새로운 데이터는 입력 데이터의(??) 선형 조합으로 구성되며, 주어진 KDE 모델의 가중치 확률 값(??)을 이용한다.

 

-End-

반응형