차원 축소

J. Hwang·2024년 8월 22일
0

차원 축소는 feature extraction 방법 중 하나로 데이터의 feature 개수를 줄이는 방법을 통칭한다.

차원 축소는 아래와 같은 장점이 있다.

  • 데이터의 복잡성을 감소시킬 수 있다.
  • 시각화하여 패턴을 발견하기 쉽다.
  • 모델의 성능을 향상시킬 수 있다.

다만 차원 축소를 할 때는 정보를 최대한 보유하고, 왜곡을 최소화할 수 있도록 신중히 진행해야 한다.

import seaborn as sns

tbl = sns.load_dataset('titanic')

PCA

Principal Component Analysis

from sklearn.decomposition import PCA

pca = PCA(n_components=2)  # 2차원으로 축소
pca_result = pca.fit_transform(tbl)

t-SNE

t-distributed Stochastic Neighbor Embedding

from sklearn.manifold import TSNE

tsne = TSNE(n_components=2, random_state=42)
tsne_result = tsne.fit_transform(tbl)

UMAP

Uniform Manifold Approximation and Projection

import umap

umap_reducer = umap.UMAP(n_components=2, random_state=42)
umap_result = umap_reducer.fit_transform(tbl)
profile
Let it code

0개의 댓글