มิติภายใน

Unsupervised Learning ใน 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
...

Scatter plot of longitude vs latitude

Unsupervised Learning ใน Python

มิติภายใน

  • มิติภายใน = จำนวนฟีเจอร์ที่ต้องใช้เพื่อประมาณชุดข้อมูล
  • แนวคิดหลักเบื้องหลังการลดมิติข้อมูล
  • การแทนค่าของตัวอย่างที่กระชับที่สุดคืออะไร?
  • ตรวจจับได้ด้วย PCA
Unsupervised Learning ใน Python

ชุดข้อมูล Versicolor

  • "versicolor" คือหนึ่งในสายพันธุ์ของดอกไอริส
  • มีเพียง 3 ฟีเจอร์: ความยาวกลีบเลี้ยง ความกว้างกลีบเลี้ยง และความกว้างกลีบดอก
  • ตัวอย่างคือจุดในปริภูมิ 3 มิติ
Unsupervised Learning ใน Python

ชุดข้อมูล Versicolor มีมิติภายในเป็น 2

  • ตัวอย่างอยู่ใกล้กับแผ่นระนาบ 2 มิติ
  • จึงสามารถประมาณได้ด้วย 2 ฟีเจอร์

Versicolor points plotted in 3d space: sepal length vs sepal width vs petal width

Unsupervised Learning ใน Python

PCA ระบุมิติภายใน

  • Scatter plot ใช้ได้เฉพาะเมื่อตัวอย่างมี 2 หรือ 3 ฟีเจอร์
  • PCA ระบุมิติภายในได้ไม่ว่าตัวอย่างจะมีฟีเจอร์กี่ตัว
  • มิติภายใน = จำนวนฟีเจอร์ PCA ที่มีความแปรปรวนมีนัยสำคัญ
Unsupervised Learning ใน Python

PCA ของตัวอย่าง Versicolor

Rotated versicolor points plotted in 3d space: PC1 vs PC2 vs PC3

Unsupervised Learning ใน Python

ฟีเจอร์ PCA เรียงตามความแปรปรวนจากมากไปน้อย

Bar plot showing pca feature number vs variance

Unsupervised Learning ใน Python

ความแปรปรวนและมิติภายใน

  • มิติภายใน คือจำนวนฟีเจอร์ PCA ที่มีความแปรปรวนมีนัยสำคัญ
  • ในตัวอย่างนี้: สองฟีเจอร์ PCA แรก
  • ดังนั้นมิติภายในคือ 2

Bar plot showing pca feature number vs variance with vertical red line between 1 and 2

Unsupervised Learning ใน 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 ใน Python

การพล็อตความแปรปรวนของฟีเจอร์ PCA

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

Bar plot showing pca feature number vs variance

Unsupervised Learning ใน Python

มิติภายในอาจมีความคลุมเครือ

  • มิติภายในเป็นแนวคิดในเชิงอุดมคติ
  • ... ไม่ได้มีคำตอบที่ถูกต้องเพียงคำตอบเดียวเสมอไป!
  • ไวน์ Piedmont: อาจโต้แย้งได้ว่าเป็น 2, 3 หรือมากกว่านั้น

Bar plot showing pca feature number vs variance of wines dataset

Unsupervised Learning ใน Python

มาฝึกกันเถอะ!

Unsupervised Learning ใน Python

Preparing Video For Download...