parafac(tensor, rank, n_iter_max=100, init='svd', svd='numpy_svd', tol=1e-08, orthogonalise=False, random_state=None, verbose=False, return_errors=False, non_negative=False, mask=None)[source]

CANDECOMP/PARAFAC decomposition via alternating least squares (ALS)

Computes a rank-rank decomposition of tensor [R17] such that,

tensor = [| factors[0], ..., factors[-1] |].


tensor : ndarray

rank : int

Number of components.

n_iter_max : int

Maximum number of iteration

init : {‘svd’, ‘random’}, optional

Type of factor matrix initialization. See initialize_factors.

svd : str, default is ‘numpy_svd’

function to use to compute the SVD, acceptable values in tensorly.SVD_FUNS

tol : float, optional

(Default: 1e-6) Relative reconstruction error tolerance. The algorithm is considered to have found the global minimum when the reconstruction error is less than tol.

random_state : {None, int, np.random.RandomState}

verbose : int, optional

Level of verbosity

return_errors : bool, optional

Activate return of iteration errors

non_negative : bool, optional

Perform non_negative PARAFAC. See non_negative_parafac.

mask : ndarray

array of booleans with the same shape as tensor should be 0 where the values are missing and 1 everywhere else. Note: if tensor is sparse, then mask should also be sparse with a fill value of 1 (or True). Allows for missing values [R18]


factors : ndarray list

List of factors of the CP decomposition element i is of shape (tensor.shape[i], rank)

errors : list

A list of reconstruction errors at each iteration of the algorithms.



T.G.Kolda and B.W.Bader, “Tensor Decompositions and Applications”, SIAM REVIEW, vol. 51, n. 3, pp. 455-500, 2009.


Tomasi, Giorgio, and Rasmus Bro. “PARAFAC and missing values.” Chemometrics and Intelligent Laboratory Systems 75.2 (2005): 163-180.