2017-09-16 101 views
0

我尝试使用Python sklearn对breast_canser数据集进行主成分分析。 并且不明白为什么特征向量的点积(3个分量)不是零?主成分分析 - 为什么特征向量的点积不是零?

frst = pca.components_[0,:] 
scnd = pca.components_[1,:] 
thrd = pca.components_[2,:] 
orth1 = np.dot(frst,scnd) 
orth2 = np.dot(scnd, thrd) 
print(orth1.real) 
print(orth2.real) 

出:

0.0

1.52655665886e-16

+3

可能重复[浮点数学是否被破坏?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Sneftel

回答

3

浮点算术并不总是100%准确的,因为计算机使用的数字的有限量来表示具有无限的数数字。 1.52655665886e-16machine epsilon的上限相对误差是由于浮点运算,所以我就当0

编辑: 您也可能会遇到此问题,如果你的矩阵没有明显的特征值。