內在維度

Unsupervised Learning in Python

Benjamin Wilson

Director of Research at lateral.io

航跡的內在維度

  • 2 個特徵:航跡上的經度與緯度
  • 資料集「看起來」是 2 維
  • 但可用單一特徵近似:沿航跡的位移
  • 其內在其實是 1 維
latitude  longitude
  50.529     41.513
  50.360     41.672
  50.196     41.835
...

經度對緯度的散佈圖

Unsupervised Learning in Python

內在維度

  • 內在維度=近似資料集所需的特徵數
  • 是降維的核心概念
  • 樣本最精簡的表示是什麼?
  • 可用 PCA 偵測
Unsupervised Learning in Python

Versicolor 資料集

  • 「versicolor」為鳶尾花的一個品種
  • 僅 3 個特徵:sepal length、sepal width、petal width
  • 樣本是 3D 空間中的點
Unsupervised Learning in Python

Versicolor 的內在維度為 2

  • 樣本接近一張平坦的 2 維薄片
  • 因此可用 2 個特徵近似

Versicolor 在 3D 空間的點圖:sepal length 對 sepal width 對 petal width

Unsupervised Learning in Python

PCA 辨識內在維度

  • 散佈圖只適用於 2 或 3 個特徵
  • PCA 可在任意特徵數下找出內在維度
  • 內在維度=具顯著變異的 PCA 特徵數
Unsupervised Learning in Python

Versicolor 樣本的 PCA

旋轉後的 versicolor 點:PC1 對 PC2 對 PC3

Unsupervised Learning in Python

PCA 特徵依變異量遞減排序

長條圖:PCA 特徵編號對變異

Unsupervised Learning in Python

變異與內在維度

  • 內在維度=具顯著變異的 PCA 特徵數
  • 本例為前兩個 PCA 特徵
  • 所以內在維度為 2

長條圖:PCA 特徵編號對變異,紅線介於 1 與 2 之間

Unsupervised Learning in Python

繪製 PCA 特徵的變異量

  • samples=versicolor 樣本的陣列
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA

pca = PCA()
pca.fit(samples)
PCA()
features = range(pca.n_components_)
Unsupervised Learning in Python

繪製 PCA 特徵的變異量

plt.bar(features, pca.explained_variance_)
plt.xticks(features)
plt.ylabel('variance')
plt.xlabel('PCA feature')
plt.show()

長條圖:PCA 特徵編號對變異

Unsupervised Learning in Python

內在維度可能不唯一

  • 內在維度是一種理想化
  • ……不一定只有一個正確答案!
  • 皮埃蒙特葡萄酒:可主張是 2、3,或更多

長條圖:葡萄酒資料集的 PCA 特徵編號對變異

Unsupervised Learning in Python

一起來練習吧!

Unsupervised Learning in Python

Preparing Video For Download...