Least squares method of linear regression model (python implementation)

Ordinary Least Square (OLS) is a method to directly solve the parameters of the linear regression equation with mathematical formulas. Taking the simplest unary linear regression as an example, Formula 6-4 shows that a series of X values ​​can be used to obtain a series of predicted values ​​Y', the purpose of which is to make the error between each pair of predicted Y' and Y ( Y- Y') is minimized. Since the errors have positive errors and negative errors, in order to avoid canceling each other, it is necessary to use the square of the error to measure. Although the absolute value can also avoid error offset, the algebraic calculation of the absolute value is not as good as the square, and it is not easy to calculate the difference. The square means the square, and the least square method means the method for finding the smallest sum of squared errors.

The reference code is as follows:

Guess you like

Origin blog.csdn.net/hu_666666/article/details/127152911