mindspore_gl.utils

utils init

mindspore_gl.utils.pca(matrix: np.ndarray, k: int = None, niter: int = 2, norm: bool = False)[source]

Perform a linear principal component analysis (PCA) on the matrix, and will return the first k dimensionality-reduced features.

Parameters
  • matrix (ndarray) – Input features, shape is \((B, F)\).

  • k (int, optional) – target dimension for dimensionality reduction. Default: None.

  • niter (int, optional) – the number of subspace iterations to conduct and it must be a nonnegative integer. Default: 2.

  • norm (bool, optional) – Whether the output is normalized. Default: False.

Returns

ndarray, Features after dimensionality reduction

Raises
Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindspore_gl.utils import pca
>>> X = np.array([[-1, 1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
>>> data = pca(X, 1)
>>> print(data)
[[ 0.33702252]
[ 2.22871406]
[ 3.6021826 ]
[-1.37346854]
[-2.22871406]
[-3.6021826 ]]