降維

Python 的 Machine Learning 前處理

James Chapman

Curriculum Manager, DataCamp

降維與 PCA

  • 非監督式學習方法
  • 結合/分解特徵空間
  • 特徵擷取-用來縮減特徵空間
  • 主成分分析
  • 線性轉換到不相關的空間
  • 在每個成分中盡量保留變異量
Python 的 Machine Learning 前處理

scikit-learn 的 PCA

from sklearn.decomposition import PCA
pca = PCA()
df_pca = pca.fit_transform(df)

print(df_pca)
[88.4583, 18.7764, -2.2379, ..., 0.0954, 0.0361, -0.0034],
[93.4564, 18.6709, -1.7887, ..., -0.0509, 0.1331, 0.0119],
[-186.9433, -0.2133, -5.6307, ..., 0.0332, 0.0271, 0.0055]
print(pca.explained_variance_ratio_)
[0.9981, 0.0017, 0.0001, 0.0001, ...]
Python 的 Machine Learning 前處理

PCA 注意事項

  • 成分不易解讀
  • 前處理流程告一段落
Python 的 Machine Learning 前處理

一起來練習吧!

Python 的 Machine Learning 前處理

Preparing Video For Download...