0

so, I have read a lot about SVD component analysis and I know that X is being factorized into unitary matrix U and diagonal matrix S, and another unitary matrix Vt and I have read that in order to make dimension reduction from N features to L where L<N then I take the first L columns of matrix U multiplied by the first L diagonal matrix values from matrix S multiplied my first L rows from matrix V.

so I did this in python:

import numpy as np


B1= np.random.random((10,2))

U, S, Vt = np.linalg.svd(B1.T, full_matrices=False)

S = np.diag(S)
V = Vt.T

print("B1=", B1.T)
print('U=', U[:,:1])
print('S=', S[:1,:1])
print('V=', V[:,:1].T)

print('mat=', np.dot(U[:,:1], np.dot(S[:1,:1], V[:,:1].T)))

so as you can see, I am generating a 10x2 matrix and then transposing it where every row represents a feature and column represents an observation so it's a 2D feature space and I am trying to make dimension reduction to reduce it to 1D feature space but here is the output where B1 is the original matrix:

B1= [[0.5507979  0.29090474 0.89294695 0.12558531 0.0514672  0.02987621
  0.64914405 0.6762549  0.02398188 0.25925245]
 [0.70814782 0.51082761 0.89629309 0.20724288 0.44080984 0.45683322
  0.27848728 0.59086282 0.55885409 0.4151012 ]]
U= [[0.64010891]
 [0.76828418]]
S= [[2.16216086]]
V= [[0.41469136 0.26763572 0.58283874 0.11081955 0.17187058 0.17117217
  0.2911348  0.41015789 0.20567839 0.22425042]]
mat= [[0.57394047 0.37041277 0.80665955 0.1533763  0.23787205 0.23690544
  0.40293592 0.56766608 0.28466269 0.31036672]
 [0.6888662  0.44458415 0.96818489 0.18408834 0.2855035  0.28434334
  0.48361973 0.68133542 0.34166349 0.37251448]]

as you notice the resultant matrix mat is still 2D matrix not 1D so I guess no dimension reduction happened so what could have gone wrong?

and another question, is there is a way to do dimension reduction using only matrix U ?

abdo Salm
  • 1,678
  • 4
  • 12
  • 22

0 Answers0