I've a matrix x (1000*25)
that contains random floats in the interval (-5,5)
. nFeatures=25
and nPoints=1000
. I'm using this code to find the eigenvalues of the covariance matrix, but I'm getting negative eigenvalues.
#centering the data
for i in range(0,nFeatures):
sum=0
for j in range(0,nPoints):
sum+=x[j][i]
for j in range(0,nPoints):
x[j][i]-=sum/nPoints
#covariance matrix and its eigenvalues & eigenvectors
c=np.dot(x.T,x)
eValue,eVector=np.linalg.eig(c)
print(eValue)
I get the output to be:
[ 1.47374029e+02 8.84275505e-13 -8.01150077e-13 -6.77987718e-13
5.19228948e-13 -4.01775609e-13 -3.55055652e-13 3.55433578e-13
-2.54817200e-13 2.51137659e-13 2.23836773e-13 1.77611044e-13
1.57643867e-13 -1.34409360e-13 1.04358065e-13 -9.31186264e-14
-8.05736392e-14 -5.69664362e-14 4.39721071e-14 3.59268864e-14
-2.84466680e-14 2.42670536e-14 2.30979465e-15 -7.18313504e-15
-9.35335475e-15]
Now since my covariance matrix is a semi-positive definite matrix, I the eigenvalues shouldn't be negative. Please help me in identifying what I'm doing wrong.
Also, I read this post, and no, there are no missing values in my dataset.