開始使用免費開始

資料前處理

在分群前先做資料前處理,可以讓分群更準確。其中一種前處理是特徵縮放,用來將資料中的自變數標準化到固定範圍,例如 0-1 或 0-100。

在這個練習中,你會對學生表現資料集(已載入為 performance)中的 parental_level_of_educationwriting_score 欄位進行分群。你會先不做任何前處理就建立並執行 k-means 模型。接著,再用特徵縮放做前處理後,重複一次相同流程。

已從 diffprivlib.models 匯入具隱私保護的 k-means 模型 KMeans。此外,也從 sklearn 匯入了標準化縮放器 StandardScaler 與降維方法 PCA

本練習屬於課程

Data Privacy and Anonymization in Python

檢視課程

動手互動練習

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

# Build the differentially private k-means model
model = KMeans(____)

# Fit the model to the data
____

# Print the inertia in the console output
print("The inertia of the private model is: ", model.inertia_)
編輯並執行程式碼