lstsq¶
- paddle.linalg. lstsq ( x, y, rcond=None, driver=None, name=None ) [source]
- 
         Computes a solution to the least squares problem of a system of linear equations. - Parameters
- 
           - x (Tensor) – A tensor with shape - (*, M, N), the data type of the input Tensor- xshould be one of float32, float64.
- y (Tensor) – A tensor with shape - (*, M, K), the data type of the input Tensor- yshould be one of float32, float64.
- rcond (float, optional) – The default value is None. A float pointing number used to determine the effective rank of - x. If- rcondis None, it will be set to max(M, N) times the machine precision of x_dtype.
- driver (str, optional) – The default value is None. The name of LAPACK method to be used. For CPU inputs the valid values are ‘gels’, ‘gelsy’, ‘gelsd, ‘gelss’. For CUDA input, the only valid driver is ‘gels’. If - driveris None, ‘gelsy’ is used for CPU inputs and ‘gels’ for CUDA inputs.
- name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name. 
 
- Returns
- 
           A tuple of 4 Tensors which is ( solution,residuals,rank,singular_values).solutionis a tensor with shape(*, N, K), meaning the least squares solution.residualsis a tensor with shape(*, K), meaning the squared residuals of the solutions, which is computed when M > N and every matrix inxis full-rank, otherwise return an empty tensor.rankis a tensor with shape(*), meaning the ranks of the matrices inx, which is computed whendriverin (‘gelsy’, ‘gelsd’, ‘gelss’), otherwise return an empty tensor.singular_valuesis a tensor with shape(*, min(M, N)), meaning singular values of the matrices inx, which is computed whendriverin (‘gelsd’, ‘gelss’), otherwise return an empty tensor.
- Return type
- 
           Tuple 
 Examples import paddle paddle.set_device("cpu") x = paddle.to_tensor([[1, 3], [3, 2], [5, 6.]]) y = paddle.to_tensor([[3, 4, 6], [5, 3, 4], [1, 2, 1.]]) results = paddle.linalg.lstsq(x, y, driver="gelsd") print(results[0]) # [[ 0.78350395, -0.22165027, -0.62371236], # [-0.11340097, 0.78866047, 1.14948535]] print(results[1]) # [19.81443405, 10.43814468, 30.56185532]) print(results[2]) # 2 print(results[3]) # [9.03455734, 1.54167950] x = paddle.to_tensor([[10, 2, 3], [3, 10, 5], [5, 6, 12.]]) y = paddle.to_tensor([[4, 2, 9], [2, 0, 3], [2, 5, 3.]]) results = paddle.linalg.lstsq(x, y, driver="gels") print(results[0]) # [[ 0.39386186, 0.10230173, 0.93606132], # [ 0.10741687, -0.29028133, 0.11892585], # [-0.05115091, 0.51918161, -0.19948854]] print(results[1]) # [] 
