다양체 학습 비교

Beginner

This tutorial is from open-source community. Access the source code

소개

이 실습에서는 비선형 차원 축소를 수행하기 위한 다양한 다양체 학습 알고리즘을 비교합니다. 이는 원본 데이터의 필수적인 특징을 보존하면서 데이터의 차원을 줄이는 것을 목표로 합니다.

차원 축소를 위한 일반적으로 사용되는 데이터셋인 S-곡선 데이터셋을 사용할 것입니다. Locally Linear Embeddings, Isomap Embedding, 다차원 스케일링, 스펙트럼 임베딩, 그리고 T-분포 확률적 이웃 임베딩과 같은 알고리즘을 사용할 것입니다.

VM 팁

VM 시작이 완료되면 왼쪽 상단 모서리를 클릭하여 Notebook 탭으로 전환하여 연습을 위한 Jupyter Notebook에 접근합니다.

때때로 Jupyter Notebook 이 완전히 로드되기까지 몇 초 정도 기다려야 할 수 있습니다. Jupyter Notebook 의 제한으로 인해 작업의 유효성 검사를 자동화할 수 없습니다.

학습 중 문제가 발생하면 Labby 에 문의하십시오. 세션 후 피드백을 제공하면 문제를 신속하게 해결해 드리겠습니다.

데이터셋 준비

S-곡선 데이터셋을 생성합니다.

import matplotlib.pyplot as plt
from matplotlib import ticker

## matplotlib < 3.2 에서 3D 투영을 위해 필요하지만 사용되지 않는 import
import mpl_toolkits.mplot3d  ## noqa: F401

from sklearn import manifold, datasets

n_samples = 1500
S_points, S_color = datasets.make_s_curve(n_samples, random_state=0)

Locally Linear Embeddings

Locally linear embedding (LLE) 는 전역적으로 비교하여 최상의 비선형 임베딩을 찾는 일련의 국소 주성분 분석 (PCA) 입니다. 표준, 국소 접선 공간 정렬, 헤시안 고유맵, 수정된 국소 선형 임베딩 등 네 가지 다른 LLE 방법을 사용할 것입니다.

params = {
    "n_neighbors": n_neighbors,
    "n_components": n_components,
    "eigen_solver": "auto",
    "random_state": 0,
}

lle_standard = manifold.LocallyLinearEmbedding(method="standard", **params)
S_standard = lle_standard.fit_transform(S_points)

lle_ltsa = manifold.LocallyLinearEmbedding(method="ltsa", **params)
S_ltsa = lle_ltsa.fit_transform(S_points)

lle_hessian = manifold.LocallyLinearEmbedding(method="hessian", **params)
S_hessian = lle_hessian.fit_transform(S_points)

lle_mod = manifold.LocallyLinearEmbedding(method="modified", **params)
S_mod = lle_mod.fit_transform(S_points)

Isomap Embedding

Isomap seeks a lower-dimensional embedding that maintains geodesic distances between all points.

isomap = manifold.Isomap(n_neighbors=n_neighbors, n_components=n_components, p=1)
S_isomap = isomap.fit_transform(S_points)

Isomap Embedding

Isomap 은 모든 점 사이의 지오데식 거리를 유지하는 저차원 임베딩을 찾습니다.

isomap = manifold.Isomap(n_neighbors=n_neighbors, n_components=n_components, p=1)
S_isomap = isomap.fit_transform(S_points)

다차원 스케일링

다차원 스케일링 (MDS) 은 원래 고차원 공간의 거리를 잘 반영하는 저차원 데이터 표현을 찾습니다.

md_scaling = manifold.MDS(
    n_components=n_components,
    max_iter=50,
    n_init=4,
    random_state=0,
    normalized_stress=False,
)
S_scaling = md_scaling.fit_transform(S_points)

비선형 차원 축소를 위한 스펙트럼 임베딩

이 구현은 그래프 라플라시안의 스펙트럼 분해를 사용하여 데이터의 저차원 표현을 찾는 라플라시안 고유맵을 사용합니다.

spectral = manifold.SpectralEmbedding(
    n_components=n_components, n_neighbors=n_neighbors
)
S_spectral = spectral.fit_transform(S_points)

T-분포 확률적 이웃 임베딩

데이터 포인트 간의 유사성을 결합 확률로 변환하고, 저차원 임베딩과 고차원 데이터의 결합 확률 사이의 쿨백 - 라이블러 발산을 최소화하려고 시도합니다.

t_sne = manifold.TSNE(
    n_components=n_components,
    perplexity=30,
    init="random",
    n_iter=250,
    random_state=0,
)
S_t_sne = t_sne.fit_transform(S_points)

요약

다양체 학습은 비선형 차원 축소 방법입니다. 이 실험에서는 S-곡선 데이터셋에 비선형 차원 축소를 수행하기 위해 국소 선형 임베딩, 아이소맵 임베딩, 다차원 스케일링, 스펙트럼 임베딩, 그리고 T-분포 확률적 이웃 임베딩과 같은 다양한 다양체 학습 알고리즘을 비교했습니다.