# pca_lowrank¶

paddle.sparse. pca_lowrank ( x, q=None, center=True, niter=2, name=None ) [source]

Performs linear Principal Component Analysis (PCA) on a sparse matrix.

Let \(X\) be the input matrix or a batch of input matrices, the output should satisfies:

\[X = U * diag(S) * V^{T}\]
Parameters
• x (Tensor) – The input tensor. Its shape should be [N, M], N and M can be arbitrary positive number. The data type of x should be float32 or float64.

• q (int, optional) – a slightly overestimated rank of \(X\). Default value is \(q=min(6,N,M)\).

• center (bool, optional) – if True, center the input tensor. Default value is True.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

• Tensor U, is N x q matrix.

• Tensor S, is a vector with length q.

• Tensor V, is M x q matrix.

tuple (U, S, V): which is the nearly optimal approximation of a singular value decomposition of a centered matrix \(X\).

Examples

```>>>

>>> format = "coo"
>>> dense_x = paddle.randn((5, 5), dtype='float64')

>>> if format == "coo":
...     sparse_x = dense_x.to_sparse_coo(len(dense_x.shape))
>>> else:
...     sparse_x = dense_x.to_sparse_csr()

>>> print("sparse.pca_lowrank API only support CUDA 11.x")
>>> # U, S, V = None, None, None
>>> # use code blow when your device CUDA version >= 11.0
>>> U, S, V = paddle.sparse.pca_lowrank(sparse_x)

>>> print(U)
[[-0.31412600,  0.44814876,  0.18390454, -0.19967630, -0.79170452],
[-0.31412600,  0.44814876,  0.18390454, -0.58579808,  0.56877700],
[-0.31412600,  0.44814876,  0.18390454,  0.78547437,  0.22292751],
[-0.38082462,  0.10982129, -0.91810233,  0.00000000,  0.00000000],
[ 0.74762770,  0.62082796, -0.23585052,  0.00000000, -0.00000000]])

>>> print(S)