当前位置:网站首页>Understanding and application of least square method
Understanding and application of least square method
2022-07-03 00:20:00 【TranSad】
The least square method is a familiar and strange thing .
In the regression problem, we often use the least square method to predict a straight line or curve to fit the real data points . The way to fit the data is to use the least square method —— Minimize the sum of squares of the difference between our predicted value and the real value .
Because it looks very basic and simple , Even with the above paragraph .
However , Why is the sum of squares ? Not to the power of one or three ? Because the first power will have positive and negative , Cannot express the actual distance ? Then take the absolute value with you …… I didn't think about this problem carefully , It seems that the least square method is the most commonly used and classic way anyway , It's similar to finding an Euclidean distance. It's just a kind of expression that everyone likes to use .
But actually , We can explore the origin of the least square method from the perspective of probability and statistics , So as to prove its rationality .
Origin of least square method :
Suppose we now have many sample points (x1,y1),(x2,y2),(x3,y3)……(xi,yi), We hope to predict a straight line :
y=wx+b To fit these sample points .
Step by step , First of all, this b Is intercept , It will look troublesome behind you , The common way in machine learning is actually x Add a constant term to 1, And then put b“ add to ” To w in , In this way, the straight line can be written as :

there θ More than the original w One more. b,x It is also better than the original x One more. 1, If you multiply it, there will be one more 1*b It's the original intercept .
So for each sample point , Our predictions y(i) by :

It is known that xi The corresponding actual value is yi, Suppose the error yi-y(i) by εi, Next, let's start with this error term εi Expand the analysis :
Now we have :
![]()
First of all, make it clear : Each data point has an error term εi, And these error terms obey the standard normal distribution ( The mean for 0 Standard deviation σ). So bring in the normal distribution formula , We have :

From the perspective of conditional probability , We hope that xi and θ In the case of combination yi Most likely to happen —— Is it very familiar , This is where we start using likelihood functions .( The likelihood function was originally sorted out )
We take every sample point into account ( Let them get tired ), The likelihood function is :

Now we hope to find a suitable θ Value maximizes this formula , The solution is very simple , Use the commonly used logarithmic method , You can get :

Make this formula the largest , Remove a constant term , Equivalent to minimizing the following formula :

In this way, we get the familiar least square method .
Application of least square method
Or for the example of fitting a straight line in a two-dimensional plane , We have decided to use the least square method , Then the target function is :
Set the format of the line as y=wx+b, Expanded :


To unite , It can be solved to get the answer :

thus , We can almost get the conclusive answer of fitting a straight line in a two-dimensional plane .
Now let's take a simple concrete example :
In a two-dimensional plane , There are three points , The values are as follows :(1,1),(2,2),(3,4), Now it is required to predict a straight line to fit these data points .
( Why three points ? Because a point has no meaning , Two points determine a straight line , At three o'clock , We need to use the least square method to fit , So choose at least three points .)
Directly use the calculated conclusion , You know :
w = [3*(1*1+2*2+3*4)-(1+2+3)(1+2+4)]/[3*(1*1+2*2+3*3)-(1+2+3)*(1+2+3)] = 3/2
b = (1+2+4)/3-3/2*(1+2+3)/3 = -2/3
So a straight line can be fitted :y=3/2x-2/3, take x=1,2,3 Carry in checking calculation , It can be found that the fitting effect is really good .
The above is just a relatively simple application scenario , We can directly use a seemingly uncomplicated conclusion . Allied , We can also use the least square method to fit the conic ( At this time, we will not set f(x)=wx+b, It is y=w*x The square of +b*x The first power of +c, And then, respectively w,b,c Find the partial derivative and then solve the equation )—— in other words , We can choose different f(x) type , Different fitting curves are obtained by the least square method .( Of course , But when the situation is complicated , It is difficult for us to get a practical answer by solving the equation , At this time, we use gradient descent to directly optimize and approximate the results .)
To sum up , This article mainly combs the origin, calculation and application of the least square method , It is also used to make it convenient to review the past and know the new ~
边栏推荐
- 论文的设计方案咋写?
- Realization of mask recognition based on OpenCV
- Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity
- Maybe you read a fake Tianlong eight
- [shutter] open the third-party shutter project
- sourcetree 详细
- 95 pages of smart education solutions 2022
- 返回二叉树中最大的二叉搜索子树的根节点
- 95页智慧教育解决方案2022
- What website can you find English literature on?
猜你喜欢

RTP 接发ps流工具改进(二)

Xcode real machine debugging
![[shutter] shutter open source project reference](/img/3f/b1d4edd8f8e8fd8e6b39548448270d.jpg)
[shutter] shutter open source project reference

95 pages of smart education solutions 2022

Monitor container runtime tool Falco

JDBC tutorial

Which software can translate an English paper in its entirety?

Practical series - free commercial video material library
![洛谷_P2010 [NOIP2016 普及组] 回文日期_折半枚举](/img/a3/55bb71d39801ceeee421a0c8ded333.png)
洛谷_P2010 [NOIP2016 普及组] 回文日期_折半枚举

Digital collection trading website domestic digital collection trading platform
随机推荐
yolov5train. py
论文的设计方案咋写?
Chapter 4 of getting started with MySQL: data types stored in data tables
Where can I find the English literature of the thesis (except HowNet)?
Many to one, one to many processing
返回二叉树中最大的二叉搜索子树的根节点
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
[reading notes] phased summary of writing reading notes
Go自定义排序
程序分析与优化 - 9 附录 XLA的缓冲区指派
TypeError: Cannot read properties of undefined (reading ***)
监控容器运行时工具Falco
yolov5detect. Py comment
What are the projects of metauniverse and what are the companies of metauniverse
RTP 接发ps流工具改进(二)
经济学外文文献在哪查?
容器运行时分析
67 page overall planning and construction plan for a new smart city (download attached)
Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity
Monitor container runtime tool Falco