在 PCA 前先進行資料縮放
當資料的各個特徵量尺不同時,通常需要先做縮放。原因是,數值較大的特徵即使變異相對較小,也可能對結果產生不成比例的影響。
combine 資料框已為你載入。
本練習屬於課程
R 的資料科學線性代數
練習說明
- 使用
scale()對combine資料的第 5 到第 12 欄進行縮放。將這個資料框命名為B,並用head()顯示部分值。 - 使用
prcomp()在此資料上執行主成分分析,並以summary()彙整此分析結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Scale columns 5-12 of combine
B <- ___(___[, 5:12])
# Print the first 6 rows of the data
___
# Summarize the principal component analysis
summary(____(B))