Least squares method