2变量线性回归的方程式 [英] Equations for 2 variable Linear Regression
问题描述
我们使用的编程语言中没有线性回归函数.我们已经实现了一个变量线性方程:
y =轴+ B
,并使用类似于此堆栈溢出答案.
我知道,随着变量的添加,这个问题在几何上会变得更加困难,但是出于我们的目的,我们只需要再添加一个:
z =轴+ By + C
在给定x,y和z数组的情况下,是否有人拥有封闭形式的方程式或使用任何语言可以求解A,B和C的代码?
因此您拥有三个线性方程式
k = aX1 + bY1 + cZ1
k = aX2 + bY2 + cZ2
k = aX3 + bY3 + cZ3
您可以做的是将其重写为matriz
| x1 y1 z1 | | a | | k |
| x2 y2 z2 | | b | = | k |
| x3 y3 y3 | | c | | k |
计算[a b c ]
做以下矩阵运算
| a | | x1 y1 z1 | | k |
| b | = inverse( | x2 y2 z2 | ) | k |
| c | | x3 y3 y3 | | k |
可以在此处找到3x3矩阵逆的公式>
We are using a programming language that does not have a linear regression function in it. We have already implemented a single variable linear equation:
y = Ax + B
and have simply calculated the A and B coefficents from the data using a solution similar to this Stack Overflow answer.
I know this problem gets geometrically harder as variables are added, but for our purposes, we only need to add one more:
z = Ax + By + C
Does anyone have the closed form equations, or code in any language that can solve for A, B and C given an array of x, y, and z's?
so you have three linear equations
k = aX1 + bY1 + cZ1
k = aX2 + bY2 + cZ2
k = aX3 + bY3 + cZ3
What you can do is rewrite it as matriz
| x1 y1 z1 | | a | | k |
| x2 y2 z2 | | b | = | k |
| x3 y3 y3 | | c | | k |
to work out [a b c ]
do the following matrix operation
| a | | x1 y1 z1 | | k |
| b | = inverse( | x2 y2 z2 | ) | k |
| c | | x3 y3 y3 | | k |
The formula for a 3x3 matrix inverse can be found here
这篇关于2变量线性回归的方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!