開始使用免費開始

以 t-SNE 視覺化穀物資料集

在影片中,你已經看到 t-SNE 應用在 iris 資料集。這個練習中,你會把 t-SNE 套用到穀物樣本的資料,並用散佈圖檢視得到的 t-SNE 特徵。你會拿到一個包含穀物樣本的陣列 samples,以及一個列出各穀物樣本品種編號的清單 variety_numbers

本練習屬於課程

Unsupervised Learning in Python

檢視課程

練習說明

  • sklearn.manifold 匯入 TSNE
  • 建立一個名為 model、且 learning_rate=200 的 TSNE 實例。
  • model 套用 .fit_transform() 方法於 samples,並將結果指定給 tsne_features
  • 選取 tsne_features 的第 0 欄,將結果指定給 xs
  • 選取 tsne_features 的第 1 欄,將結果指定給 ys
  • 以 t-SNE 特徵 xsys 繪製散佈圖。若要依穀物品種著色,請加入額外關鍵字引數 c=variety_numbers

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import TSNE
____

# Create a TSNE instance: model
model = ____

# Apply fit_transform to samples: tsne_features
tsne_features = ____

# Select the 0th feature: xs
xs = tsne_features[:,0]

# Select the 1st feature: ys
ys = tsne_features[:,1]

# Scatter plot, coloring by variety_numbers
____
plt.show()
編輯並執行程式碼