產生分類用資料集
要找到同時滿足多種條件的真實資料集並不容易,而且即使蒐集到,也可能牽涉隱私疑慮。作為替代方案,你可以使用資料集產生器,建立與真實世界資料相近的模擬資料集。
在本練習中,你將為一個 3 分類問題建立大型資料集。為了能以散佈圖輕鬆視覺化產生的資料,我們提供了自訂函式 plot_data_points()。
本練習屬於課程
Data Privacy and Anonymization in Python
練習說明
- 從
sklearn.datasets匯入用來產生分類資料集的對應函式。 - 產生
5000個樣本、4個特徵、每個類別1個叢集、共3個類別,且類別分離度為2。 - 列印產生資料的 shape。
- 檢視產生的散佈圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the function for generating classification datasets
from sklearn.datasets import ____
# Generate 5000 samples with 4 features, 1 cluster per class, 3 classes, and class separation of 2
x, y = ____
# Inspect the generated data shape
print(____)
# Inspect the resulting data points in a 2 dimensional scatter plot
plot_data_points(x, y)