垂直线的最小二乘方程
给定以下 2d 点:
213 106.8
214 189
214 293.4
213 324
223 414
我想找到穿过它们的最小二乘垂直轴线的方程。我的计划是得到一个直线方程,这样我就可以测试后续点到最小二乘线的距离。
谢谢
Given the following 2d points:
213 106.8
214 189
214 293.4
213 324
223 414
I want to find an equation for the least squares vertical axis line that runs through them. My plan is to get a line equation so I can test subsequent points for their distances to that least squares line.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
严格来说,最小二乘拟合没有为垂直线定义(因为
每个点的误差是平行于 Y 轴测量的)。
然而,如果你交换X和Y,你可以找到具有最好最少的水平线
正方形适合。它的计算结果只是 Y 坐标值的平均值:
水平线的方程就是 y = b。
每个点 (xi, yi) 的误差为 (yi - b)。
误差平方和为 SSE = sum( (yi - b)2)。我们希望
找出使 SSE 最小化的 b 值。对 SSE 求偏导数
相对于 b 并将其设置为零:
sum(-2(yi - b)) = 0
简化,
sum(yi) - Nb = 0
且
b = sum(yi)/N
因此,在您的情况下,对 X 坐标求平均值即可得出 X 坐标
最适合您的点的垂直线。
Strictly speaking, a least squares fit is not defined for a vertical line (since
the error for each point is measured parallel to the Y axis).
However, if you swap X and Y, you can find the horizontal line with the best least
squares fit. It works out to simply the mean of the Y coordinate values:
The equation for a horizontal line is simply y = b.
The error at each point (xi, yi) is (yi - b).
The sum of the squares of the errors is SSE = sum( (yi - b)2). We wish
to find the value of b that minimizes SSE. Take the partial derivative of SSE with
respect to b and set it to zero:
sum(-2(yi - b)) = 0
Simplifying,
sum(yi) - Nb = 0
and
b = sum(yi)/N
So in your case, averaging the X coordinates gives you the X coordinate of
the vertical line that best fits your points.
最通用的解决方案是应用 总最小二乘法
这会找到 (a, b, d) 到最小化垂直距离的平方和 (ax+by=d (a^2+b^2=1): |ax + by – d|)。这可以处理垂直线,例如 0x+1y=0。
然而,这实现起来有点困难,所以@Jim Lewis 提供的解决方案可能很好而且更实用。
The most generic solution would be to apply Total Least Squares
This finds (a, b, d) to minimize the sum of squared perpendicular distances (ax+by=d (a^2+b^2=1): |ax + by – d|). This can handle vertical lines, such as 0x+1y=0.
However, this is a bit more difficult to implement, so the solution offered by @Jim Lewis might be fine and more practical..
如果您希望最佳拟合线是垂直的(即 x = 常数),则 y 值无关紧要。只需取 x 值平方平均值的平方根即可。
If you want the line of best fit to be vertical (i.e. x = constant), the y-values are irrelevant. Simply take the square root of the mean of the squares of the x-values.