其他分享
首页 > 其他分享> > 主成分分析

主成分分析

作者:互联网

import numpy as np

data = np.array([[2.5, 2.4], [0.5, 0.7], [2.2, 2.9], [1.9, 2.2], [3.1, 3.0], 
                 [2.3, 2.7], [2, 1.6], [1, 1.1], [1.5, 1.6], [1.1, 0.9]])

x1 = sum(data[:, 0]) / 10.0

y1 = sum(data[:, 1]) / 10.0

DataAdjust = data - [x1, y1]

cov1 = np.array(np.cov(DataAdjust[:, 0], data[:, 1]))

eig1, eig2 = np.linalg.eig(cov1)

a = eig2[:, 0] if eig1[0] > eig1[1] else eig2[:, 1]
b = a.T

res = np.dot(DataAdjust, a)
print(res)

标签:分析,1.6,eig2,eig1,成分,DataAdjust,np,data
来源: https://blog.csdn.net/m0_47660709/article/details/120682913