為分群產生資料集
合成資料完全合法,並符合全球各地的隱私法規。它是相較於原始資料更重視隱私的可行替代方案。make_blobs() 函式可用來產生符合高斯(或常態)分佈的資料點。
在這個練習中,你將產生一個包含 15000 個樣本的資料集。
numpy 已以 np 匯入,並且本題已提供自訂函式 plot_data_points() 供你使用。
本練習屬於課程
Data Privacy and Anonymization in Python
練習說明
- 從
datasets模組匯入用於產生分群資料集的對應函式。 - 產生一個包含
15000個樣本、2個特徵、2個中心,且叢集標準差為3的資料集。 - 列印所產生資料的形狀(shape)。
- 用 2 維散佈圖檢視產生的資料點。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the function from the datasets module for generating clustering datasets
from sklearn.datasets import ____
# Generate a dataset with 15000 rows, 2 features, 2 centers, and a cluster std of 3
x, labels = ____
# Print the shape of the resulting generated data
print(____)
# See the resulting data points in a 2 dimensional scatter plot
plot_data_points(x, labels)