当前位置:网站首页>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 ~
边栏推荐
- Wechat applet basic learning (wxss)
- 返回二叉树中最大的二叉搜索子树的根节点
- TypeError: Cannot read properties of undefined (reading ***)
- JDBC tutorial
- 35 pages dangerous chemicals safety management platform solution 2022 Edition
- Where can I find foreign papers?
- Leetcode relaxation question - day of the week
- 流媒体技术优化
- What are the recommended thesis translation software?
- How to set automatic reply for mailbox and enterprise mailbox?
猜你喜欢

实用系列丨免费可商用视频素材库

What website can you find English literature on?

Practical series - free commercial video material library

maya渔屋建模
![Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation](/img/4a/ab732c41ea8a939fa0983fec475622.png)
Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation

直击产业落地!飞桨重磅推出业界首个模型选型工具

35 pages dangerous chemicals safety management platform solution 2022 Edition

Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity

How to apply for company email when registering in company email format?

附加:token;(没写完,别看…)
随机推荐
Interface automation coverage statistics - used by Jacobo
Top Devops tool chain inventory
ArrayList analysis 2: pits in ITR, listiterator, and sublist
Open source | Wenxin big model Ernie tiny lightweight technology, which is accurate and fast, and the effect is fully open
流媒体技术优化
Chapter 3 of getting started with MySQL: database creation and operation
Missing number
JS interviewer wants to know how much you understand call, apply, bind no regrets series
MFC文件操作
In February 2022, the ranking list of domestic databases: oceanbase regained its popularity with "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
How QT exports data to PDF files (qpdfwriter User Guide)
判断二叉树是否为满二叉树
Additional: token; (don't read until you finish writing...)
容器运行时分析
Is the multitasking loss in pytoch added up or backward separately?
顶级 DevOps 工具链大盘点
英文论文有具体的格式吗?
CADD course learning (4) -- obtaining proteins without crystal structure (Swiss model)
附加:token;(没写完,别看…)
Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)