開始使用免費開始

標準化特徵

在進行 kNN 距離計算前,務必要用 scale() 函式先將作為輸入的特徵做標準化。標準化可避免平均值或變異數較大的特徵過度影響 kNN 距離分數。

本練習屬於課程

R 中的異常偵測入門

檢視課程

練習說明

  • wine 資料套用 summary() 函式,計算 pHalcohol 的平均值、最小值與最大值。
  • 使用 scale() 函式建立標準化後的 wine 資料,命名為 wine_scaled
  • wine_scaled 使用 summary() 函式,檢查平均值與數值範圍是否已改變。

動手互動練習

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

# Without standardization, features have different scales
summary(wine)

# Standardize the wine columns
wine_scaled <- ___

# Standardized features have similar means and quartiles
___(___)
編輯並執行程式碼