4.7.8.1.2. statsmodels.tools.linalg.lstsq

statsmodels.tools.linalg.lstsq(a, b, cond=None, overwrite_a=0, overwrite_b=0)[source]

Compute least-squares solution to equation :m:`a x = b`

Compute a vector x such that the 2-norm :m:`|b - a x|` is minimised.

Parameters:

a : array, shape (M, N)

b : array, shape (M,) or (M, K)

cond : float

Cutoff for ‘small’ singular values; used to determine effective rank of a. Singular values smaller than rcond*largest_singular_value are considered zero.

overwrite_a : boolean

Discard data in a (may enhance performance)

overwrite_b : boolean

Discard data in b (may enhance performance)

Returns:

x : array, shape (N,) or (N, K) depending on shape of b

Least-squares solution

residues : array, shape () or (1,) or (K,)

Sums of residues, squared 2-norm for each column in :m:`b - a x` If rank of matrix a is < N or > M this is an empty array. If b was 1-d, this is an (1,) shape array, otherwise the shape is (K,)

rank : integer

Effective rank of matrix a

s : array, shape (min(M,N),)

Singular values of a. The condition number of a is abs(s[0]/s[-1]).

Raises LinAlgError if computation does not converge