Python 使用 PCA 进行降维 - 代码示例
import numpy as np import matplotlib.pyplot as plt from sklearn.decomposition import PCA
x = np.array([[1, 2], [1.5, 1.8], [5, 8], [8, 8], [1, 0.6], [9, 11]]) ########## Begin ########## #降维 #主成分数量为2 pca = PCA(n_components=2)
#拟合数据 pca.fit(x)
#贡献比 X_Contribution = pca.explained_variance_ratio_ print(X_Contribution)
#生成降维后的数据 X_reduction = pca.transform(x) print(X_reduction) ########## End ##########
原文地址: https://www.cveoy.top/t/topic/onQg 著作权归作者所有。请勿转载和采集!