The Method of Least Squares
Steven J. Miller¤
Mathematics Department
Brown University
Providence, RI 02912
Abstract
The Method of Least Squares is a procedure to determine the best fit line to data; the
proof uses simple calculus and linear algebra. The basic problem is to find the best fit
straight line y = ax + b given that, for n 2 f1; : : : ;Ng, the pairs (xn; yn) are observed.
The method easily generalizes to finding the best fit of the form
y = a1f1(x) + ¢ ¢ ¢ + cKfK(x); (0.1)
it is not necessary for the functions fk to be linearly in x – all that is needed is that y is to
be a linear combination of these functions.
Contents
1 Description of the Problem 1
2 Probability and Statistics Review 2
3 The Method of Least Squares 4
1 Description of the Problem
Often in the real world one expects to find linear relationships between variables. For example,
the force of a spring linearly depends on the displacement of the spring: y = kx (here y is
the force, x is the displacement of the spring from rest, and k is the spring constant). To test
the proposed relationship, researchers go to the lab and measure what the force is for various
displacements. Thus they assemble data of the form (xn; yn) for n 2 f1; : : : ;Ng; here yn is
the observed force in Newtons when the spring is displaced xn meters.
¤E-mail: sjmiller@math.brown.edu
1
5 10 15 20
20
40
60
80
100
Figure 1: 100 “simulated” observations of displacement and force (k = 5).
Unfortunately, it is extremely unlikely that we will observe a perfect linear relationship.
There are two reasons for this. The first is experimental error; the second is that the underlying
relationship may not be exactly linear, but rather only approximately linear. See Figure 1 for
a simulated data set of displacements and forces for a spring with spring constant equal to 5.
The Method of Least Squares is a procedure, requiring just some calculus and linear algebra,
to determine what the “best fit” line is to the data. Of course, we need to quantify what
we mean by “best fit”, which will require a brief review of some probability and statistics.
A careful analysis of the proof will show that the method is capable of great generalizations.
Instead of finding the best fit line, we could find the best fit given by any finite linear
combinations of specified functions. Thus the general problem is given functions f1; : : : ; fK,
find values of coefficients a1; : : : ; aK such that the linear combination
y = a1f1(x) + ¢ ¢ ¢ + aKfK(x) (1.1)
is the best approximation to the data.
2 Probability and Statistics Review
We give a quick introduction to the basic elements of probability and statistics which we need
for the Method of Least Squares; for more details see [BD, CaBe, Du, Fe, Kel, LF, MoMc].
Given a sequence of data x1; : : : ; xN, we define the mean (or the expected value) to be
2
(x1 + ¢ ¢ ¢ + xN)=N. We denote this by writing a line above x: thus
x =
1
N
XN
n=1
xn: (2.2)
The mean is the average value of the data.
Consider the following two sequences of data: f10; 20; 30; 40; 50g and f30; 30; 30; 30; 30g.
Both sets have the same mean; however, the first data set has greater variation about the mean.
This leads to the concept of variance, which is a useful tool to quantify how much a set of data
fluctuates about its mean. The variance of fx1; : : : ; xNg, denoted by ¾2
x, is
¾2
x =
1
N
XN
n=1
(xi ¡ x)2; (2.3)
the standard deviation ¾x is the square root of the variance:
¾x =
vuut
1
N
XN
n=1
(xi ¡ x)2: (2.4)
Note that if the x’s have units of meters then the variance ¾2
x has units of meters2, and the
standard deviation ¾x and the mean x have units of meters. Thus it is the standard deviation
that gives a good measure of the deviations of the x’s around their mean.
There are, of course, alternate measures one can use. For example, one could consider
1
N
XN
n=1
(xn ¡ x): (2.5)
Unfortunately this is a signed quantity, and large positive deviations can cancel with large
negatives. In fact, the definition of the mean immediately implies the above is zero! This,
then, would be a terrible measure of the variability in data, as it is zero regardless of what the
values of the data are.
We can rectify this problem by using absolute values. This leads us to consider
1
N
XN
n=1
jxn ¡ xj: (2.6)
While this has the advantage of avoiding cancellation of errors (as well as having the same
units as the x’s), the absolute value function is not a good function analytically. It is not
differentiable. This is primarily why we consider the standard deviation (the square root of
the variance) – this will allow us to use the tools from calculus.
3
We can now quantify what we mean by “best fit”. If we believe y = ax+b, then y¡(ax+b)
should be zero. Thus given observations
f(x1; y1); : : : ; (xN; yN)g; (2.7)
we look at
fy1 ¡ (ax1 + b); : : : ; yN ¡ (axN + b)g: (2.8)
The mean should be small (if it is a good fit), and the variance will measure how good of a fit
we have.
Note that the variance for this data set is
¾2
y¡(ax+b) =
1
N
XN
n=1
(yn ¡ (axn + b))2 : (2.9)
Large errors are given a higher weight than smaller errors (due to the squaring). Thus our procedure
favors many medium sized errors over a few large errors. If we used absolute values to
measure the error (see equation (2.6)), then all errors are weighted equally; however, the absolute
value function is not differentiable, and thus the tools of calculus become inaccessible.
3 The Method of Least Squares
Given data f(x1; y1); : : : ; (xN; yN)g, we may define the error associated to saying y = ax + b
by
E(a; b) =
XN
n=1
(yn ¡ (axn + b))2 : (3.10)
This is just N times the variance of the data set fy1¡(ax1+b); : : : ; yn¡(axN +b)g. It makes
no difference whether or not we study the variance or N times the variance as our error, and
note that the error is a function of two variables.
The goal is to find values of a and b that minimize the error. In multivariable calculus we
learn that this requires us to find the values of (a; b) such that
@E
@a
= 0;
@E
@b
= 0: (3.11)
Note we do not have to worry about boundary points: as jaj and jbj become large, the fit will
clearly get worse and worse. Thus we do not need to check on the boundary.
Differentiating E(a; b) yields
@E
@a
=
XN
n=1
2 (yn ¡ (axn + b)) ¢ (¡xn)
@E
@b
=
XN
n=1
2 (yn ¡ (axn + b)) ¢ 1: (3.12)
4
Setting @E=@a = @E=@b = 0 (and dividing by 2) yields
XN
n=1
(yn ¡ (axn + b)) ¢ xn = 0
XN
n=1
(yn ¡ (axn + b)) = 0: (3.13)
We may rewrite these equations as
Ã
XN
n=1
x2
n
!
a +
Ã
XN
n=1
xn
!
b =
XN
n=1
xnyn
Ã
XN
n=1
xn
!
a +
Ã
XN
n=1
1
!
b =
XN
n=1
yn: (3.14)
We have obtained that the values of a and b which minimize the error (defined in (3.10))
satisfy the following matrix equation:
0
@
PN
n=1 x2
n
PN
n=1 xn
PN
n=1 xn
PN
n=1 1
1
A
0
@
a
b
1
A =
0
@
PN
n=1 xnyn
PN
n=1 yn
1
A: (3.15)
We will show the matrix is invertible, which implies
0
@
a
b
1
A =
0
@
PN
n=1 x2
n
PN
n=1 xn
PN
n=1 xn
PN
n=1 1
1
A
¡1 0
@
PN
n=1 xnyn
PN
n=1 yn
1
A: (3.16)
Denote the matrix by M. The determinant of M is
detM =
XN
n=1
x2
n ¢
XN
n=1
1 ¡
XN
n=1
xn ¢
XN
n=1
xn: (3.17)
As
x =
1
N
XN
n=1
xn; (3.18)
we find that
detM = N
XN
n=1
x2
n ¡ (Nx)2
= N2
Ã
1
N
XN
n=1
x2
n ¡ x2
!
= N2 ¢
1
N
XN
n=1
(xn ¡ x)2; (3.19)
5
where the last equality follows from simple algebra. Thus, as long as all the xn are not equal,
detM will be non-zero and M will be invertible.
Thus we find that, so long as the x’s are not all equal, the best fit values of a and b are
obtained by solving a linear system of equations; the solution is given in (3.16).
Remark 3.1. The data plotted in Figure 1 was obtained by letting xn = 5 + :2n and then
letting yn = 5xn plus an error randomly drawn from a normal distribution with mean zero and
standard deviation 4 (n 2 f1; : : : ; 100g). Using these values, we find a best fit line of
y = 4:99x + :48; (3.20)
thus a = 4:99 and b = :48. As the expected relation is y = 5x, we expected a best fit value of
a of 5 and b of 0.
While our value for a is very close to the true value, our value of b is significantly off.
We deliberately chose data of this nature to indicate the dangers in using the Method of Least
Squares. Just because we know 4:99 is the best value for the slope and :48 is the best value
for the y-intercept does not mean that these are good estimates of the true values. The theory
needs to be supplemented with techniques which provide error estimates. Thus we want to
know something like, given this data, there is a 99% chance that the true value of a is in
(4:96; 5:02) and the true value of b is in (¡:22; 1:18); this is far more useful than just knowing
the best fit values.
If instead we used
Eabs(a; b) =
XN
n=1
jyn ¡ (axn + b)j ; (3.21)
then numerical techniques yield that the best fit value of a is 5:03 and the best fit value of b
is less than 10¡10 in absolute value. The difference between these values and those from the
Method of Least Squares is in the best fit value of b (the least important of the two parameters),
and is due to the different ways of weighting the errors.
Exercise 3.2. Generalize the method of least squares to find the best fit quadratic to y = ax2+
bx+c (or more generally the best fit degreempolynomial to y = amxm+am¡1xm¡1+¢ ¢ ¢+a0).
While for any real world problem, direct computation determines whether or not the resulting
matrix is invertible, it is nice to be able to prove the determinant is always non-zero
for the best fit line (if all the x’s are not equal).
Exercise 3.3. If the x’s are not all equal, must the determinant be non-zero for the best fit
quadratic or the best fit cubic?
Looking at our proof of the Method of Least Squares, we note that it was not essential that
we have y = ax + b; we could have had y = af(x) + bg(x), and the arguments would have
6
proceeded similarly. The difference would be that we would now obtain
0
@
PN
n=1 f(xn)2 PN
n=1 f(xn)g(xn)
PN
n=1 f(xn)g(xn)
PN
n=1 g(xn)2
1
A
0
@
a
b
1
A =
0
@
PN
n=1 f(xn)yn
PN
n=1 g(xn)yn
1
A: (3.22)
Exercise 3.4. Consider the g
วิธีกำลังสองน้อยที่สุดSteven J. Miller¤ภาควิชาคณิตศาสตร์มหาวิทยาลัยสีน้ำตาลจัดเตรียม RI 02912บทคัดย่อวิธียกกำลังสองน้อยที่สุดคือ วิธีการตรวจสอบข้อมูล บรรทัดพอดีสุด ที่หลักฐานใช้ง่ายแคลคูลัสพีชคณิตเชิงเส้น ปัญหาพื้นฐานคือการ หาขนาดที่พอดีเส้นตรง y = ax + b ระบุว่า สำหรับ n 2 f1 : : : ;Ng จะสังเกตคู่ (xn, yn)วิธีการง่าย ๆ generalizes เพื่อหาขนาดที่พอดีของแบบฟอร์มy = a1f1(x) + cKfK(x) ลอกลอกลอก (0.1)จะไม่จำเป็นสำหรับ fk ฟังก์ชันเชิงเส้นใน x – ทั้งหมดที่จำเป็นคือ y จะการรวมกันเชิงเส้นฟังก์ชันเหล่านี้ได้เนื้อหาคำอธิบาย 1 ของปัญหา 1ความน่าเป็น 2 และตรวจสอบสถิติ 23 วิธีกำลังสองน้อยที่สุด 41 รายละเอียดของปัญหาบ่อยครั้งในโลกจริง ที่หนึ่งต้องหาความสัมพันธ์เชิงเส้นระหว่างตัวแปร ตัวอย่างแรงสปริงเชิงเส้นขึ้นอยู่กับปริมาณกระบอกสูบของฤดูใบไม้ผลิ: y = kx (นี่ y คือแรง x จะแทนของฤดูใบไม้ผลิจากส่วนเหลือ และ k เป็นค่าคงสปริง) ในการทดสอบนำเสนอความสัมพันธ์ นักวิจัยไปตรวจ และวัดแรงมีไว้เพื่ออะไรต่าง ๆdisplacements ดังนั้น จะรวบรวมข้อมูลของแบบฟอร์ม (xn, yn) สำหรับ f1 n 2 : : : ;Ng นี่คือ ynบังคับให้สังเกตใน Newtons เมื่อฤดูใบไม้ผลิพลัดถิ่น xn เมตร¤E เมล์: sjmiller@math.brown.edu15 10 15 2020406080100รูปที่ 1:100 "จำลอง" สังเกตปริมาณกระบอกสูบและบังคับ (k = 5)อับ ไม่น่ามากว่า เราจะสังเกตเห็นความสัมพันธ์เชิงเส้นที่เหมาะสมมีอยู่สองประการนี้ ครั้งแรกเป็นการทดลองผิดพลาด ที่สองคือต้นแบบไม่อาจเป็นความสัมพันธ์เชิงเส้นตรง แต่ค่อนข้างประมาณเท่าเส้น ดูรูปที่ 1 สำหรับเป็นชุดจำลองข้อมูลของ displacements และกองกำลังของสปริงมีค่าคงของสปริงเท่ากับ 5วิธียกกำลังสองน้อยที่สุดคือ วิธีการ ต้องการเพียงบางแคลคูลัสและพีชคณิตเชิงเส้นเพื่อกำหนดบรรทัด "เหมาะ" ที่เป็นข้อมูล แน่นอน เราจำเป็นต้องกำหนดปริมาณอะไรเราหมายถึง โดย "เหมาะ" ซึ่งจะต้องมีการสรุปย่อบางความน่าเป็นและสถิติวิเคราะห์อย่างระมัดระวังของหลักฐานจะแสดงว่าวิธีการของ generalizations ดีแทนที่จะค้นหาส่วนพอดีกับบรรทัด เราสามารถหาขนาดที่พอดีได้รับ โดยการจำกัดเส้นชุดของฟังก์ชันที่ระบุ ดังนั้น ปัญหาทั่วไปจะกำหนดฟังก์ชัน f1 : : : ; fKค้นหาค่าของสัมประสิทธิ์ a1 : : : ; aK ให้การรวมกันเชิงเส้นy = a1f1(x) + aKfK(x) (1.1) ลอกลอกลอกมีประมาณข้อมูลที่ดีที่สุดตรวจสอบสถิติและความน่าเป็น 2เราให้การแนะนำองค์ประกอบพื้นฐานของความน่าเป็นและสถิติซึ่งเราต้องการด่วนสำหรับวิธีการกำลังสองน้อยที่สุด สำหรับรายละเอียดเพิ่มเติมดู [BD เคบ Du, Fe, Kel, LF, MoMc]กำหนดลำดับของข้อมูล x 1 : : : ; xN เรากำหนดค่าเฉลี่ย (หรือมูลค่าคาดไว้) จะ2(x 1 + ลอกลอกลอก + xN) = N เราแสดงนี้ โดยเขียนบรรทัดเหนือ x:ดังนั้นx =1NXNn = 1xn: (2.2)ค่าเฉลี่ยคือ ค่าเฉลี่ยของข้อมูลพิจารณาลำดับที่สองต่อไปนี้ของข้อมูล: f10 20 30 40 50g และ f30 30 30 30 30 กรัมทั้งสองชุดมีค่าเฉลี่ยเหมือนกัน อย่างไรก็ตาม ข้อมูลชุดแรกมีความผันแปรมากขึ้นเกี่ยวกับค่าเฉลี่ยนี้นำไปสู่แนวคิดของผลต่าง ซึ่งเป็นเครื่องมือที่มีประโยชน์เพื่อกำหนดปริมาณจำนวนชุดของข้อมูลแกว่งไปมาเกี่ยวกับค่าเฉลี่ยของ ความแปรปรวนของ fx1 : : : ; xNg สามารถบุ โดย ¾2เป็น x¾2x =1NXNn = 1(สิ¡ x) 2 (2.3)¾x ส่วนเบี่ยงเบนมาตรฐานเป็นค่ารากที่สองของความแปรปรวน:¾x =vuut1NXNn = 1(สิ¡ x) 2: (2.4)หมายเหตุว่า ถ้ารายมีหน่วยเมตรแล้วต่าง ¾2x มีหน่วยของ meters2 และส่วนเบี่ยงเบนมาตรฐาน ¾x และ x หมายถึงมีหน่วยเมตร ดังนั้น จึงเป็นส่วนเบี่ยงเบนมาตรฐานที่ทำให้การวัดความแตกต่างของรายรอบหมายถึงความดีได้ แน่นอน หนึ่งสามารถใช้มาตรการอื่น ตัวอย่าง หนึ่งอาจพิจารณา1NXNn = 1(xn ¡ x): (2.5)แต่นี้เป็นปริมาณที่ได้รับการรับรอง และความเบี่ยงเบนของค่าบวกขนาดใหญ่สามารถยกเลิกที่ มีขนาดใหญ่ค่าลบ ในความเป็นจริง การกำหนดค่าเฉลี่ยทันทีหมายถึงข้างต้นเป็นศูนย์ นี้แล้ว จะเป็นการวัดความแปรผันในข้อมูล น่ากลัวเป็นศูนย์ไม่ว่าสิ่งค่าของข้อมูลได้เราสามารถแก้ปัญหานี้ โดยใช้ค่าสัมบูรณ์ นี้นำไปให้พิจารณา1NXNn = 1jxn ¡ xj: (2.6)ขณะนี้มีข้อดีของการหลีกเลี่ยงข้อผิดพลาดในการยกเลิก (และมีเหมือนกันหน่วยเป็นราย), ฟังก์ชันค่าสัมบูรณ์คือไม่ ดีฟังก์ชัน analytically มันไม่ใช่differentiable นี่คือทำไมเราพิจารณาส่วนเบี่ยงเบนมาตรฐาน (ค่ารากของแปรปรวน) – นี้จะช่วยให้เราสามารถใช้เครื่องมือจากแคลคูลัส3เราตอนนี้สามารถกำหนดปริมาณเราหมายความว่า โดย "เหมาะ" ถ้าเราเชื่อว่า y = ax + b แล้ว y¡(ax+b)ควรเป็นศูนย์ ดังนั้น ให้สังเกตf (x 1, y1); : : : ; (xN, yN) g (2.7)เราดู¡ fy1 (ax1 + บี); : : : ; yN g: ¡ (เอเอ็กซ์เอ็น + b) (2.8)ค่าเฉลี่ยควรมีขนาดเล็ก (ถ้าเป็นพอดี), และผลต่างจะวัดวิธีที่ดีของความพอดีเรามีหมายเหตุผลต่างสำหรับข้อมูลชุดนี้ว่า¾2y¡(ax+b) =1NXNn = 1(yn ¡ (เอเอ็กซ์เอ็น + b)) 2: (2.9)ข้อผิดพลาดขนาดใหญ่จะให้น้ำหนักสูงกว่าข้อผิดพลาดน้อย (เพราะ squaring) ดังนั้นกระบวนการของเราสนับสนุนข้อผิดพลาดขนาดปานกลางข้อผิดพลาดน้อยมาก ถ้าเราใช้ค่าสัมบูรณ์ข้อผิดพลาดในการวัด (ดูสมการ (2.6)), แล้วรันจะถ่วงน้ำหนักเท่า ๆ กัน อย่างไรก็ตาม สัมบูรณ์ค่าฟังก์ชันไม่ differentiable และดังนั้น เครื่องมือของแคลคูลัสสามารถเข้าถึง3 วิธีการกำลังสองน้อยสุดให้ข้อมูล f (x 1, y1); : : : ; (xN, yN) g เราอาจกำหนดข้อผิดพลาดที่เกี่ยวข้องกับว่า y = ax + bโดยE(a; b) =XNn = 1(yn ¡ (เอเอ็กซ์เอ็น + b)) 2: (3.10)นี้เป็นเพียง N ครั้งความแปรปรวนของชุดข้อมูล fy1¡(ax1+b) : : : ; กรัม yn¡ (เอเอ็กซ์เอ็น + บี) มันทำให้ไม่แตกต่างหรือไม่เราศึกษาผลต่างหรือ N เวลาต่างเป็นข้อผิดพลาดของเรา และโปรดสังเกตว่า ข้อผิดพลาดฟังก์ชันสองตัวแปรเป้าหมายคือหาค่าของแบบ และ b ที่ลดข้อผิดพลาด ในแคลคูลัส multivariable เราเรียนรู้ว่า ต้องไปหาค่าของ (แบบ b) ให้@E@a= 0@E@b= 0: (3.11)หมายเหตุเราไม่ต้องกังวลเกี่ยวกับจุดขอบเขต: เป็น jaj jbj กลายเป็นขนาดใหญ่ พอจะชัดเจนได้แย่ลงและแย่ลง ดังนั้น เราไม่จำเป็นต้องตรวจสอบขอบเขตการขึ้นต้น E(a; b) อัตราผลตอบแทน@E@a=XNn = 1หมายเลข (yn ¡ (เอเอ็กซ์เอ็น + b)) 2 (¡xn)@E@b=XNn = 1หมายเลข 2 (yn ¡ (เอเอ็กซ์เอ็น + b)) 1: (3.12)4การตั้งค่า @E =@ตัว = @E = @b = 0 (และหาร ด้วย 2) ทำให้XNn = 1(yn ¡ (เอเอ็กซ์เอ็น + b)) หมายเลข xn = 0XNn = 1(yn ¡ (เอเอ็กซ์เอ็น + b)) = 0: (3.13)เราอาจเขียนสมการเหล่านี้เป็นใช้XNn = 1x 2n!เป็น +ใช้XNn = 1xn!b =XNn = 1xnynใช้XNn = 1xn!เป็น +ใช้XNn = 11!b =XNn = 1yn: (3.14)เราได้รับที่ค่าของตัว และ b ซึ่งลดข้อผิดพลาด (กำหนดไว้ใน (3.10))ตามสมการของเมทริกซ์ต่อไปนี้:0@PNn = 1 x 2nPNn = 1 xnPNn = 1 xnPNn = 1 11A0@การb1=เป็น0@PNn = 1 xnynPNn = 1 yn1A: (3.15)เราจะแสดงเป็นเมตริกซ์สามารถหาอินเวอร์ส ซึ่งหมายถึง0@การb1=เป็น0@PNn = 1 x 2nPNn = 1 xnPNn = 1 xnPNn = 1 11A¡1 0@PNn = 1 xnynPNn = 1 yn1A: (3.16)แสดงเมตริกซ์ โดย M ดีเทอร์มิแนนต์ของ M คือdetM =XNn = 1x 2หมายเลข nXNn = 11 ¡XNn = 1หมายเลข xnXNn = 1xn: (3.17)เป็นx =1NXNn = 1xn (3.18)เราพบว่าdetM = NXNn = 1x 2n ¡ (Nx) 2= N2ใช้1NXNn = 1x 2¡ n x 2!= เลข N21NXNn = 1(xn ¡ x) 2 (3.19)5ซึ่งความเสมอภาคสุดท้ายต่อจากเรื่องพีชคณิต ดังนั้น ตราบ xn ทั้งหมดไม่เท่ากันdetM จะไม่ใช่ศูนย์ และ M จะสามารถหาอินเวอร์สดังนั้น เราพบว่า เป็นรายไม่เท่ากันทั้งหมด ส่วนที่พอดีกับค่าของตัว และ b คือได้ โดยการแก้สมการ ระบบเชิงเส้น การแก้ปัญหาได้ใน (3.16)หมายเหตุ 3.1 ข้อมูลที่พล็อตในรูปที่ 1 ได้รับ โดยทำให้ xn = 5 +: 2n แล้วให้ yn = 5xn บวกข้อผิดพลาดในการออกแบบสุ่มจากการแจกแจงปกติด้วยค่าเฉลี่ยเป็นศูนย์ และส่วนเบี่ยงเบนมาตรฐาน 4 (f1 n 2;:::; 100 กรัม) ใช้ค่าเหล่านี้ เราค้นหาบรรทัดพอดีสุดของy = 4:99 x +: 48 (3.20)ดังนั้นการ = 4:99 และ b =: 48 เป็นความสัมพันธ์ที่คาดไว้คือ y = 5 x เราคาดว่า ส่วนพอดีกับค่าของ5 และ b 0ขณะที่คุณค่าในการเป็นมากคุณค่าแท้จริง คุณค่าของบีอยู่ออกมากเราตั้งใจเลือกของธรรมชาตินี้เพื่อบ่งชี้อันตรายในการใช้วิธีการอย่างน้อยสี่เหลี่ยม เพียง เพราะเรารู้ว่า 4:99 เป็นค่าดีสำหรับความชัน และ: 48 มีค่าสุดสำหรับตัดแกน y ไม่ได้หมายความ ว่า เหล่านี้เป็นประเมินที่ดีของค่าจริง ทฤษฎีต้องถูกเสริม ด้วยเทคนิคที่ให้ประเมินผิดพลาด ดังนั้น เราต้องการรู้ว่าสิ่งที่ต้องการ ให้ข้อมูล มีโอกาส 99% ที่คุณค่าแท้จริงของการเป็น(4:96; 5:02) และคุณค่าแท้จริงของบี (¡: 22; 1:18); นี้มีประโยชน์มากขึ้นกว่าเพียงแค่รู้ส่วนพอดีกับค่าถ้าเราใช้แทนEabs(a; b) =XNn = 1เจ jyn ¡ (เอเอ็กซ์เอ็น + บี) (3.21)แล้วเทคนิคตัวเลขผลตอบแทนที่ดีที่สุดเหมาะสมกับค่าของความเป็น 5:03 และดีสุดเหมาะสมกับค่าของ bไม่น้อยกว่า 10¡10 ในค่าสัมบูรณ์ ความแตกต่างระหว่างค่าเหล่านี้และจากการวิธีกำลังสองน้อยสุดมีค่าพอดีสุดของ b (อย่างน้อยสำคัญที่พารามิเตอร์สอง),และเนื่องจากวิธีการต่าง ๆ ของน้ำหนักข้อผิดพลาดแบบฝึกหัดที่ 3.2 ทั่วไปวิธีการกำลังสองน้อยสุดในการค้นหาดีที่สุดพอดีกำลังสองการ y = ax2 +bx + c (หรือโดยทั่วไปมากขึ้นสุดพอดี degreempolynomial ให้ y = amxm + am¡1xm¡1 + ลอกลอกลอก + a0)สำหรับปัญหาโลก คำนวณโดยตรงกำหนดหรือไม่เกิดเมทริกซ์นี้สามารถหาอินเวอร์ส มันจะดีเพื่อให้สามารถพิสูจน์ดีเทอร์มิแนนต์เสมอไม่ใช่ศูนย์สำหรับส่วนพอดีกับบรรทัด (ถ้ารายทั้งหมดไม่เท่ากัน)แบบฝึกหัดที่ 3.3 ถ้าไม่เท่ากันทุกราย ดีเทอร์มิแนนต์ต้องไม่เป็นศูนย์ในสุดพอดีกำลังสองหรือลูกบาศก์ของเหมาะสมที่สุดดูที่หลักฐานของเราของวิธีน้อยเหลี่ยม เราหมายเหตุว่า ไม่จำเป็นที่เรามี y = ax + b เราไม่ได้มี y = af(x) + bg(x) และอาร์กิวเมนต์จะมี6ครอบครัวในทำนองเดียวกัน ความแตกต่างจะที่เราจะตอนนี้ขอรับ0@PNn = 1 f (xn) 2 PNn = 1 f(xn)g(xn)PNn = 1 f(xn)g(xn)PNn = 1 g (xn) 21A0@การb1=เป็น0@PNn = 1 f (xn) ynPNn = yn g 1 (xn)1A: (3.22)แบบฝึกหัดที่ 3.4 พิจารณา g
การแปล กรุณารอสักครู่..

The Method of Least Squares
Steven J. Miller¤
Mathematics Department
Brown University
Providence, RI 02912
Abstract
The Method of Least Squares is a procedure to determine the best fit line to data; the
proof uses simple calculus and linear algebra. The basic problem is to find the best fit
straight line y = ax + b given that, for n 2 f1; : : : ;Ng, the pairs (xn; yn) are observed.
The method easily generalizes to finding the best fit of the form
y = a1f1(x) + ¢ ¢ ¢ + cKfK(x); (0.1)
it is not necessary for the functions fk to be linearly in x – all that is needed is that y is to
be a linear combination of these functions.
Contents
1 Description of the Problem 1
2 Probability and Statistics Review 2
3 The Method of Least Squares 4
1 Description of the Problem
Often in the real world one expects to find linear relationships between variables. For example,
the force of a spring linearly depends on the displacement of the spring: y = kx (here y is
the force, x is the displacement of the spring from rest, and k is the spring constant). To test
the proposed relationship, researchers go to the lab and measure what the force is for various
displacements. Thus they assemble data of the form (xn; yn) for n 2 f1; : : : ;Ng; here yn is
the observed force in Newtons when the spring is displaced xn meters.
¤E-mail: sjmiller@math.brown.edu
1
5 10 15 20
20
40
60
80
100
Figure 1: 100 “simulated” observations of displacement and force (k = 5).
Unfortunately, it is extremely unlikely that we will observe a perfect linear relationship.
There are two reasons for this. The first is experimental error; the second is that the underlying
relationship may not be exactly linear, but rather only approximately linear. See Figure 1 for
a simulated data set of displacements and forces for a spring with spring constant equal to 5.
The Method of Least Squares is a procedure, requiring just some calculus and linear algebra,
to determine what the “best fit” line is to the data. Of course, we need to quantify what
we mean by “best fit”, which will require a brief review of some probability and statistics.
A careful analysis of the proof will show that the method is capable of great generalizations.
Instead of finding the best fit line, we could find the best fit given by any finite linear
combinations of specified functions. Thus the general problem is given functions f1; : : : ; fK,
find values of coefficients a1; : : : ; aK such that the linear combination
y = a1f1(x) + ¢ ¢ ¢ + aKfK(x) (1.1)
is the best approximation to the data.
2 Probability and Statistics Review
We give a quick introduction to the basic elements of probability and statistics which we need
for the Method of Least Squares; for more details see [BD, CaBe, Du, Fe, Kel, LF, MoMc].
Given a sequence of data x1; : : : ; xN, we define the mean (or the expected value) to be
2
(x1 + ¢ ¢ ¢ + xN)=N. We denote this by writing a line above x: thus
x =
1
N
XN
n=1
xn: (2.2)
The mean is the average value of the data.
Consider the following two sequences of data: f10; 20; 30; 40; 50g and f30; 30; 30; 30; 30g.
Both sets have the same mean; however, the first data set has greater variation about the mean.
This leads to the concept of variance, which is a useful tool to quantify how much a set of data
fluctuates about its mean. The variance of fx1; : : : ; xNg, denoted by ¾2
x, is
¾2
x =
1
N
XN
n=1
(xi ¡ x)2; (2.3)
the standard deviation ¾x is the square root of the variance:
¾x =
vuut
1
N
XN
n=1
(xi ¡ x)2: (2.4)
Note that if the x’s have units of meters then the variance ¾2
x has units of meters2, and the
standard deviation ¾x and the mean x have units of meters. Thus it is the standard deviation
that gives a good measure of the deviations of the x’s around their mean.
There are, of course, alternate measures one can use. For example, one could consider
1
N
XN
n=1
(xn ¡ x): (2.5)
Unfortunately this is a signed quantity, and large positive deviations can cancel with large
negatives. In fact, the definition of the mean immediately implies the above is zero! This,
then, would be a terrible measure of the variability in data, as it is zero regardless of what the
values of the data are.
We can rectify this problem by using absolute values. This leads us to consider
1
N
XN
n=1
jxn ¡ xj: (2.6)
While this has the advantage of avoiding cancellation of errors (as well as having the same
units as the x’s), the absolute value function is not a good function analytically. It is not
differentiable. This is primarily why we consider the standard deviation (the square root of
the variance) – this will allow us to use the tools from calculus.
3
We can now quantify what we mean by “best fit”. If we believe y = ax+b, then y¡(ax+b)
should be zero. Thus given observations
f(x1; y1); : : : ; (xN; yN)g; (2.7)
we look at
fy1 ¡ (ax1 + b); : : : ; yN ¡ (axN + b)g: (2.8)
The mean should be small (if it is a good fit), and the variance will measure how good of a fit
we have.
Note that the variance for this data set is
¾2
y¡(ax+b) =
1
N
XN
n=1
(yn ¡ (axn + b))2 : (2.9)
Large errors are given a higher weight than smaller errors (due to the squaring). Thus our procedure
favors many medium sized errors over a few large errors. If we used absolute values to
measure the error (see equation (2.6)), then all errors are weighted equally; however, the absolute
value function is not differentiable, and thus the tools of calculus become inaccessible.
3 The Method of Least Squares
Given data f(x1; y1); : : : ; (xN; yN)g, we may define the error associated to saying y = ax + b
by
E(a; b) =
XN
n=1
(yn ¡ (axn + b))2 : (3.10)
This is just N times the variance of the data set fy1¡(ax1+b); : : : ; yn¡(axN +b)g. It makes
no difference whether or not we study the variance or N times the variance as our error, and
note that the error is a function of two variables.
The goal is to find values of a and b that minimize the error. In multivariable calculus we
learn that this requires us to find the values of (a; b) such that
@E
@a
= 0;
@E
@b
= 0: (3.11)
Note we do not have to worry about boundary points: as jaj and jbj become large, the fit will
clearly get worse and worse. Thus we do not need to check on the boundary.
Differentiating E(a; b) yields
@E
@a
=
XN
n=1
2 (yn ¡ (axn + b)) ¢ (¡xn)
@E
@b
=
XN
n=1
2 (yn ¡ (axn + b)) ¢ 1: (3.12)
4
Setting @E=@a = @E=@b = 0 (and dividing by 2) yields
XN
n=1
(yn ¡ (axn + b)) ¢ xn = 0
XN
n=1
(yn ¡ (axn + b)) = 0: (3.13)
We may rewrite these equations as
Ã
XN
n=1
x2
n
!
a +
Ã
XN
n=1
xn
!
b =
XN
n=1
xnyn
Ã
XN
n=1
xn
!
a +
Ã
XN
n=1
1
!
b =
XN
n=1
yn: (3.14)
We have obtained that the values of a and b which minimize the error (defined in (3.10))
satisfy the following matrix equation:
0
@
PN
n=1 x2
n
PN
n=1 xn
PN
n=1 xn
PN
n=1 1
1
A
0
@
a
b
1
A =
0
@
PN
n=1 xnyn
PN
n=1 yn
1
A: (3.15)
We will show the matrix is invertible, which implies
0
@
a
b
1
A =
0
@
PN
n=1 x2
n
PN
n=1 xn
PN
n=1 xn
PN
n=1 1
1
A
¡1 0
@
PN
n=1 xnyn
PN
n=1 yn
1
A: (3.16)
Denote the matrix by M. The determinant of M is
detM =
XN
n=1
x2
n ¢
XN
n=1
1 ¡
XN
n=1
xn ¢
XN
n=1
xn: (3.17)
As
x =
1
N
XN
n=1
xn; (3.18)
we find that
detM = N
XN
n=1
x2
n ¡ (Nx)2
= N2
Ã
1
N
XN
n=1
x2
n ¡ x2
!
= N2 ¢
1
N
XN
n=1
(xn ¡ x)2; (3.19)
5
where the last equality follows from simple algebra. Thus, as long as all the xn are not equal,
detM will be non-zero and M will be invertible.
Thus we find that, so long as the x’s are not all equal, the best fit values of a and b are
obtained by solving a linear system of equations; the solution is given in (3.16).
Remark 3.1. The data plotted in Figure 1 was obtained by letting xn = 5 + :2n and then
letting yn = 5xn plus an error randomly drawn from a normal distribution with mean zero and
standard deviation 4 (n 2 f1; : : : ; 100g). Using these values, we find a best fit line of
y = 4:99x + :48; (3.20)
thus a = 4:99 and b = :48. As the expected relation is y = 5x, we expected a best fit value of
a of 5 and b of 0.
While our value for a is very close to the true value, our value of b is significantly off.
We deliberately chose data of this nature to indicate the dangers in using the Method of Least
Squares. Just because we know 4:99 is the best value for the slope and :48 is the best value
for the y-intercept does not mean that these are good estimates of the true values. The theory
needs to be supplemented with techniques which provide error estimates. Thus we want to
know something like, given this data, there is a 99% chance that the true value of a is in
(4:96; 5:02) and the true value of b is in (¡:22; 1:18); this is far more useful than just knowing
the best fit values.
If instead we used
Eabs(a; b) =
XN
n=1
jyn ¡ (axn + b)j ; (3.21)
then numerical techniques yield that the best fit value of a is 5:03 and the best fit value of b
is less than 10¡10 in absolute value. The difference between these values and those from the
Method of Least Squares is in the best fit value of b (the least important of the two parameters),
and is due to the different ways of weighting the errors.
Exercise 3.2. Generalize the method of least squares to find the best fit quadratic to y = ax2+
bx+c (or more generally the best fit degreempolynomial to y = amxm+am¡1xm¡1+¢ ¢ ¢+a0).
While for any real world problem, direct computation determines whether or not the resulting
matrix is invertible, it is nice to be able to prove the determinant is always non-zero
for the best fit line (if all the x’s are not equal).
Exercise 3.3. If the x’s are not all equal, must the determinant be non-zero for the best fit
quadratic or the best fit cubic?
Looking at our proof of the Method of Least Squares, we note that it was not essential that
we have y = ax + b; we could have had y = af(x) + bg(x), and the arguments would have
6
proceeded similarly. The difference would be that we would now obtain
0
@
PN
n=1 f(xn)2 PN
n=1 f(xn)g(xn)
PN
n=1 f(xn)g(xn)
PN
n=1 g(xn)2
1
A
0
@
a
b
1
A =
0
@
PN
n=1 f(xn)yn
PN
n=1 g(xn)yn
1
A: (3.22)
Exercise 3.4. Consider the g
การแปล กรุณารอสักครู่..

วิธีกำลังสองต่ำสุด
สตีเวน เจ. มิลเลอร์¤
สีน้ำตาลภาควิชาคณิตศาสตร์มหาวิทยาลัยโพรวิเดนซ์ ริ 02912 นามธรรม
วิธีกำลังสองต่ำสุดเป็นขั้นตอนเพื่อตรวจสอบเส้นพอดีข้อมูล ;
หลักฐานใช้แคลคูลัสง่ายและพีชคณิตเชิงเส้น ปัญหาพื้นฐานคือการค้นหาที่ดีที่สุดเหมาะกับเส้นตรง y = ax
b ระบุว่า ใน 2 F1 n ; : : : ; ng คู่ ( คริสเตียน ; ใน )
)วิธีการค้นหาได้อย่างง่ายดายเช่นนี้ได้ขยายพอดีกับที่ดีที่สุดของรูปแบบ
y = a1f1 ( X ) ¢¢¢ ckfk ( x ) ; ( 0.1 )
ไม่จําเป็นสําหรับการทํางานที่เป็นเส้นตรง FK X –ทั้งหมดที่จำเป็นคือว่า Y คือ
เป็นการรวมกันเชิงเส้นของฟังก์ชันเหล่านี้ .
เนื้อหารายละเอียดของปัญหา 1
1
2 ความน่าจะเป็นและสถิติตรวจสอบ 2
3 วิธีกำลังสองต่ำสุด 5 รายละเอียดของปัญหา
1มักจะอยู่ในโลกจริง หนึ่งคาดว่าจะพบความสัมพันธ์เชิงเส้นระหว่างตัวแปร ตัวอย่างเช่น
แรงสปริงเชิงเส้นขึ้นอยู่กับการเคลื่อนที่ของฤดูใบไม้ผลิ : Y = KX ( ที่นี่ y
แรง , X คือการกระจัดของฤดูใบไม้ผลิจากส่วนที่เหลือ และ k คือค่าคงตัวสปริง ) ทดสอบ
เสนอความสัมพันธ์ นักวิจัยไปห้องแล็บ และวัดสิ่งที่บังคับให้กรรมต่าง ๆ
ดังนั้น พวกเขารวบรวมข้อมูลรูปแบบ ( คริสเตียน ; ใน ) 2 F1 n ; : : : ; ng ; ที่นี่ในนั้น
สังเกตแรงในนิวตันเมื่อฤดูใบไม้ผลิพลัดถิ่นเมตรคริสเตียน .
¤ E-mail : คณิตศาสตร์ sjmiller @ สีน้ำตาล . edu
1
5 10 15 20
20 40 60
รูปที่ 1 : 80 100 100 " จำลอง " การสังเกตของการเคลื่อนที่และแรง ( k = 5 ) .
แต่เป็นไปได้ยากมากที่เราจะสังเกตสมบูรณ์แบบ
ความสัมพันธ์เชิงเส้น .มีสองเหตุผลนี้ อย่างแรกคือข้อผิดพลาดทดลอง ; ที่สองคือพื้นฐานที่
ความสัมพันธ์อาจไม่ตรงเส้น แต่เพียงประมาณแบบเชิงเส้น รูปที่ 1 สำหรับ
จำลองชุดข้อมูลสูงสุดและบังคับให้ฤดูใบไม้ผลิกับฤดูใบไม้ผลิที่คงที่เท่ากับ 5 .
วิธีกำลังสองต่ำสุดเป็นขั้นตอนที่ต้องแค่แคลคูลัสและพีชคณิตเชิงเส้น ,
เพื่อตรวจสอบว่า " พอดี " บรรทัด คือข้อมูล แน่นอนเราต้องการที่จะหาสิ่งที่
เราหมายถึง " พอดี " ซึ่งจะต้องทบทวนของความน่าจะเป็นและสถิติ การวิเคราะห์ระมัดระวังของหลักฐานที่จะแสดงให้เห็นว่าวิธีการที่สามารถทั่วไปมาก .
แทนการหาเส้นพอดีกับที่ดีที่สุดที่เราสามารถหาที่เหมาะสมที่สุดให้โดย
มีเส้นจำกัดชุดของฟังก์ชันที่กำหนด ดังนั้น ปัญหา ทั่วไป จะได้รับฟังก์ชัน F1 ; : : : ; FK
หาค่าสัมประสิทธิ์ A1 ; : : : ; และที่
การรวมกันเชิงเส้น y = a1f1 ( X ) ¢¢¢ akfk ( X ) ( 1.1 )
เป็นประมาณที่ดีที่สุดข้อมูล ความน่าจะเป็น และ
2 รีวิว สถิติเราให้แนะนำตัวกับองค์ประกอบพื้นฐานของความน่าจะเป็นและสถิติ ที่เราต้องการ
สำหรับวิธีกำลังสองต่ำสุด ; สำหรับรายละเอียดเพิ่มเติมเห็น [ BD เคบ du , เหล็ก , แคล ถ้า momc , ] .
ได้รับลำดับของ X1 ข้อมูล ; : : : ; คริสเตียน เรากำหนดหมายถึง ( หรือคิดเป็นค่า )
2
( x1 ¢¢¢คริสเตียน ) = นี้ เราแสดงโดยเขียนบรรทัดข้างต้นดังนี้
x = x
1
n
n = 1
ซินซิน : ( 2.2 )
หมายถึงค่าเฉลี่ยของข้อมูล .
พิจารณาต่อไปนี้สองลําดับของข้อมูล : F10 ; 20 ; 30 ; 40 ; 50 กรัม และ F30 ; 30 ;30 ; 30 ; 30 .
ทั้งชุดจะมีความหมายเดียวกัน อย่างไรก็ตาม ก่อนชุดข้อมูลมีรูปแบบมากขึ้นเกี่ยวกับค่าเฉลี่ย .
นี้นำไปสู่แนวคิดของความแปรปรวน ซึ่งเป็นเครื่องมือที่มีประโยชน์ที่จะวัดเท่าใดชุดข้อมูล
fluctuates เกี่ยวกับหมายถึง ความแปรปรวนของ fx1 ; : : : ; xng เขียนแทนด้วย¾ 2
x ,
¾ 2
x =
1
n
ซิน
n = 1
( Xi ¡ X ) 2 ( 2.3 )
x ส่วนเบี่ยงเบนมาตรฐาน¾คือรากที่สองของความแปรปรวน :
¾ x = vuut
1
n
คริสเตียน
n = 1
( Xi ¡ X ) 2 : ( 2.4 )
หมายเหตุว่า ถ้า x มีหน่วยเมตร แล้ว ความ¾ 2
x มีหน่วย meters2 และส่วนเบี่ยงเบนมาตรฐาน¾
x และ x มีหน่วยคือเมตร ดังนั้นมันจึงเป็นส่วนเบี่ยงเบนมาตรฐาน
ที่ให้วัดที่ดีของการเบี่ยงเบนของ X ประมาณค่าเฉลี่ยของพวกเขา .
แน่นอนว่ามีมาตรการอื่นที่สามารถใช้ ตัวอย่างเช่นหนึ่งอาจพิจารณา
1
n
ซิน
n = 1
( คริสเตียน¡ x ) : ( 25 )
แต่นี้เป็นค่าเซ็นสัญญา ปริมาณ บวกขนาดใหญ่สามารถยกเลิกด้วยฟิล์มใหญ่
ในความเป็นจริง , ความหมายของหมายถึงทันทีนัยข้างต้นคือศูนย์ แบบนี้
แล้วจะเป็นวัดที่น่ากลัวของความแปรปรวนในข้อมูล มัน เป็น ศูนย์ ไม่ว่าค่าของข้อมูล
.
เราสามารถจัดการกับปัญหานี้ โดยการใช้ค่าที่แน่นอน นี้ทำให้เราพิจารณา
1
n
ซินN = XJ ¡ 1 ( 2.6 )
jxn ขณะ นี้ มี ประโยชน์ หลีกเลี่ยงการยกเลิกข้อผิดพลาด ( รวมทั้งมีหน่วยเดียวกัน
เป็น X ) , ฟังก์ชันค่าสัมบูรณ์ไม่ใช่ฟังก์ชั่นที่ดีวิเคราะห์ . มันไม่ได้
Differentiable . นี้เป็นหลัก เราจึงพิจารณาค่าส่วนเบี่ยงเบนมาตรฐาน ( รากที่สองของความแปรปรวน
และนี้จะช่วยให้เราสามารถใช้เครื่องมือจาก
3
แคลคูลัสตอนนี้เราสามารถหาสิ่งที่เราหมายถึงโดย " พอดี " ถ้าเราเชื่อว่า y = ax B , Y ¡ ( ขวาน B )
ควรจะเป็นศูนย์ ดังนั้นให้สังเกต
f ( x1 ; y1 ) ; : : : ; ( คริสเตียน ; ใน ) g ; ( 2.7 )
เราดู fy1 ¡ ( ax1 B ) ; : : : ; ใน¡ ( AXN B ) g :
( 2.8 ) หมายถึงควรจะเล็ก ( ถ้ามันพอดี ดี ) และความแปรปรวนจะวัดอย่างไรดี พอดี
ทราบว่าเรามี ความแปรปรวนสำหรับข้อมูลชุดนี้เป็น¾ 2
Y ¡ ( ขวาน B ) =
1
n
n = 1
ซิน( ใน¡ ( AXN B ) 2 : ( 2.9 )
ข้อผิดพลาดขนาดใหญ่จะได้รับน้ำหนักมากกว่าข้อผิดพลาดเล็ก ( เนื่องจาก squaring ) ดังนั้น กระบวนการของเราโปรดปรานมาก
ขนาดกลางขนาดใหญ่กว่าข้อผิดพลาดข้อผิดพลาดไม่กี่ ถ้าเราใช้ค่าแน่นอน
วัดผิดพลาด ( ดูสมการ ( 2.6 ) ) แล้วข้อผิดพลาดทั้งหมดจะหนักเท่า ๆ กัน อย่างไรก็ตาม ฟังก์ชันค่าสัมบูรณ์
ไม่หาอนุพันธ์ได้และดังนั้นจึงเป็นเครื่องมือของแคลคูลัสที่กลายเป็นไม่สามารถเข้าถึงได้ .
3 วิธีกำลังสองต่ำสุด
ให้ข้อมูล f ( x1 ; y1 ) ; : : : ; ( คริสเตียน ; ใน ) g เราอาจจะระบุข้อผิดพลาดที่เกี่ยวข้องกับบอกว่า y = ax
โดย E ( B ; b )
n = =
ซิน 1
( ใน¡ ( AXN B ) 2 : ( 3.10 )
n ครั้งนี้เป็นเพียงความแปรปรวนของข้อมูลชุด fy1 ¡ ( ax1 B ) ; : : : ; ใน¡ ( AXN B ) g .
มันทำให้ไม่แตกต่างกันหรือไม่ เราศึกษาความแปรปรวนหรือ N ครั้งแปรปรวนเป็นข้อผิดพลาดของเราและ
ทราบว่าข้อผิดพลาดเป็นฟังก์ชันสองตัวแปร .
เป้าหมายคือเพื่อหาค่าของ a และ b ที่สามารถลดข้อผิดพลาด ในวิชาแคลคูลัสเรา
เรียนรู้นี้ต้องการให้เราหาค่าของ ( 2 ) เช่น e
@
@ a = 0 ;
@ @
E
b = 0 ( 3.11 )
หมายเหตุเราไม่ต้องกังวลเกี่ยวกับจุดขอบเขต :และเป็น jbj JAJ กลายเป็นใหญ่ พอดีจะ
ว่าแย่ลง และแย่ลง ดังนั้น เราไม่ต้องดูขอบเขต ทั้ง E (
; B ) ผลผลิต
@
@
=
E เป็นคริสเตียน
n = 1
2 ( ใน¡ ( AXN B ) ¢ ( ¡คริสเตียน )
@
@
=
b e
n = 1
ซิน 2 ( ใน¡ ( AXN B ) ¢ 1 : ( 3.12 )
4
ตั้งค่า @ E = @ = @ = @ E B = 0 ( และหารด้วย 2 ) ผลผลิต
ซิน
n = 1
( ใน¡ ( AXN B ) ¢ซินซิน
n = 0 =
= 1
( ใน¡ ( AXN B ) = 0 ( 3.13 )
เราอาจเขียนสมการเหล่านี้เป็นÃ
คริสเตียน
n = 1
X2
-
! !
a
n = 1 Ãซินซิน
! !
b =
ซิน
n = 1
xnyn
n = 1 Ãซินซิน
! !
a
Ãซิน
n = 1
1
!
b =
ซิน
n = 1 ( 3.14 )
ในที่สุดเราได้รับนั้นค่าของ a และ b ซึ่งลดความผิดพลาด ( ที่กำหนดไว้ใน ( 3.10 )
ตอบสนองต่อไปนี้เมทริกซ์สมการ :
0
@
PN
n = 1 X2
n
PN
n = 1 ซิน
PN
n = 1 คริสเตียน
PN
n = 1
1
A
0
@
A
B
1
=
0
@
PN
n = 1 xnyn
PN
n = 1 ใน
1
: ( 3.15 )
เราจะแสดงเมทริกซ์คือ invertible ซึ่งหมายถึง
0
@
A
B
1
=
0
@
PN
n = 1 X2
n
PN
n = 1 คริสเตียน
PN
n = 1 คริสเตียน
PN
n = 1
1
A
¡ 1 0
@
PN
n = 1 xnyn
PN
n = 1 ใน
1
:
( 3.16 ) แทนเมตริกซ์โดย ปัจจัยที่ detm m
=
ซิน
n = 1
X2
n ¢
ซิน
n = 1
1
¡ซิน
n = 1
ซินซิน¢
n = 1
ซิน : ( 3.17 )
x = 1
เป็น n
คริสเตียน
n = 1
ซิน ( 3.18 )
เราพบว่า detm = N
ซิน
n = 1
X2
n ¡ ( NX )
2 = 2
Ã
1
n
ซิน
n = 1
X2
n ¡ X2
!
=
1
n
2 ¢ซิน
n = 1
( คริสเตียน¡ X ) 2 ( 3.19 )
5
ที่ความเท่าเทียมกันเมื่อตามจากพีชคณิตอย่างง่าย ดังนั้นตราบใดที่ทุกคริสเตียนจะไม่เท่ากัน
detm จะไม่เป็นศูนย์และ M จะ invertible .
ดังนั้นเราจึงพบว่า ตราบใดที่ X ไม่ได้ทั้งหมดเท่ากับ ค่าเหมาะที่สุดของ A และ B
ได้โดยการแก้ระบบสมการเชิงเส้น ; โซลูชั่นที่ระบุใน ( 3.16 )
หมายเหตุ 3.1 . ข้อมูลวางแผนในรูปที่ 1 ได้ โดยปล่อยให้ซิน = 5 : 2 แล้ว
ปล่อยใน = 5xn พลัสข้อผิดพลาดสุ่มจากการแจกแจงแบบปกติด้วยค่าเฉลี่ยและส่วนเบี่ยงเบนมาตรฐานที่ 4 ,
( N 2 F1 ; : : : ; 100g ) การใช้ค่าเหล่านี้ เราพบที่ดีที่สุดเหมาะสมกับสายของ
y = 4:99x : 48 ; ( 3.20 ) จึง 4:99 =
b = : 48 ขณะที่คาดว่าความสัมพันธ์ คือ Y = 5x , เราคาดว่าพอดีค่า
A และ B 5 0
ในขณะที่มูลค่าของเราที่ใกล้ชิดกับมูลค่าที่แท้จริงค่าของ b เป็นทางปิด
เราจงใจเลือกข้อมูลในลักษณะนี้เพื่อบ่งชี้ถึงอันตรายในการใช้วิธีอย่างน้อย
สี่เหลี่ยม เพราะเรารู้ว่า 4:99 เป็นค่าที่ดีที่สุดสำหรับความลาดชันและ 48 เป็นค่าที่ดีที่สุด
สำหรับ y-intercept ไม่ได้หมายความว่าเหล่านี้เป็นประมาณการที่ดีของค่าจริง ทฤษฎี
ต้องเสริมด้วยเทคนิคที่ให้ประมาณการผิดพลาดดังนั้นเราต้องการ
รู้แบบนี้ ให้ข้อมูลนี้มี 99% โอกาสที่มูลค่าที่แท้จริงของใน
( ทำลาย ; 5:02 ) และมูลค่าที่แท้จริงของ บี ( ¡ : 22 ; 1 : 18 ) ; นี้เป็นประโยชน์มากกว่าแค่รู้
พอดีค่า ถ้าเราใช้ EABS (
; B ) =
ซิน
n = 1
jyn ¡ ( AXN B ) j ;
( 3.21 ) แล้วเทคนิคเชิงตัวเลขผลตอบแทนที่เหมาะสมที่สุดคือ มูลค่าของ 5:03 และดีที่สุดเหมาะสมกับค่าของ b
น้อยกว่า 10 ¡ 10 ในค่าสัมบูรณ์ ความแตกต่างระหว่างค่าเหล่านี้และจาก
วิธีกำลังสองต่ำสุดอยู่พอดีค่า B ( ที่สำคัญอย่างน้อยสองพารามิเตอร์ ) ,
และเนื่องจากวิธีที่แตกต่างของน้ำหนักข้อผิดพลาด .
ออกกำลังกาย 3.2 . อนุมานวิธีกำลังสองต่ำสุดเพื่อค้นหาดีที่สุดเหมาะสมที่จะ ax2
y =BX C ( หรือมากกว่าโดยทั่วไปพอดี degreempolynomial Y = amxm เป็น¡ 1xm ¡ 1 ¢¢¢ A0 ) .
ในขณะที่ใด ๆ ในโลกแห่งความเป็นจริง ปัญหา ในการคำนวณโดยตรงจะกำหนดหรือไม่เป็นผล
เมทริกซ์ invertible , มันเป็นสิ่งที่ดีที่จะสามารถพิสูจน์หนึ่งเสมอไม่เป็น
สำหรับสายพอดี ที่ดีที่สุด ( ถ้า x ไม่เท่ากับ ) .
ออกกำลังกาย 3.3 . ถ้า x เป็นทั้งหมดไม่เท่ากับต้องกำหนดไม่เป็นศูนย์สำหรับพอดี
กำลังสอง หรือพอดีกับที่ดีที่สุดลูกบาศก์ ?
ดูหลักฐานของวิธีกำลังสองต่ำสุด เราทราบว่ามันไม่ได้จำเป็นว่าเราต้อง y = ax
b ; เราสามารถมี Y = AF ( x ) BG ( x ) , และอาร์กิวเมนต์จะมี
6
ก็ทำนองเดียวกัน ความแตกต่างจะเป็นที่เราตอนนี้จะได้รับ
0
@
PN
n = 1 F ( คริสเตียน ) 2 PN
n = 1 F ( คริสเตียน ) g ( คริสเตียน )
PN
n = 1 F ( คริสเตียน ) g ( คริสเตียน )
?N = 1 กรัม ( คริสเตียน ) 2
1
A
0
@
A
B
1
=
0
@
PN
n = 1 F ( คริสเตียน ) ใน
PN
n = 1 กรัม ( คริสเตียน ) ใน
1
: ( ไทย )
ออกกำลังกาย 3.4 . พิจารณาก.
การแปล กรุณารอสักครู่..
