[SciPy-User] bug in svd ?

pratik pratik.mallya@gmail....
Sun Sep 25 11:15:15 CDT 2011


Hi Scipy users,
I was using the scikits.learn package for pca analysis, but couldn't get
the desired principal components (which were apparant from the structure
of the data). So i just took the svd of the covariance matrix of the
input data (after making the mean 0, of course). But on examining the
singular values, i found that they are *NOT sorted in decreasing order*
(as they should be; although i can of course sort it myself now, the
scikits.learn package depends upon this fact) This is also mentioned in
the code; that the singular values should be sorted:

    Returns
    -------
    u : ndarray
        Unitary matrix.  The shape of `u` is (`M`, `M`) or (`M`, `K`)
        depending on value of ``full_matrices``.
    s : ndarray
        The singular values, sorted so that ``s[i] >= s[i+1]``.  `s` is
        a 1-d array of length min(`M`, `N`).
    v : ndarray
        Unitary matrix of shape (`N`, `N`) or (`K`, `N`), depending on
        ``full_matrices``.

I am attaching the code and the data for you to examine. Just print out
the values of the s array in ipython to see what i mean...

Best,

-- 
Pratik Mallya
https://netfiles.uiuc.edu/mallya2/www/index.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p3pca.py
Type: text/x-python
Size: 476 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20110925/2764c840/attachment-0001.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vl1.wav
Type: audio/x-wav
Size: 177990 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20110925/2764c840/attachment-0001.wav 


More information about the SciPy-User mailing list