简体   繁体   English

使用math.net进行多元回归

[英]Multiple Regression with math.net

Hello I am trying to get multiple regression with math.net and I am a little confused. 您好,我试图通过math.net进行多元回归,但我有些困惑。

var xdata = new DenseMatrix(
 new double[,]{{1, 36, 66, 45, 32},
             {1, 37, 68, 12, 2},
             {1, 47, 64, 78, 34},
             {1, 32, 53, 56, 32},
             {1, 1, 101, 24, 90}});

        var ydata = new double[] { 15, 20, 25, 55, 95 };

        var X = DenseMatrix.CreateFromColumns(new[] { new DenseVector(xdata.Length, 1), new DenseVector(xdata) });
        var y = new DenseVector(ydata);

        var p = X.QR().Solve(y);
        var a = p[0];
        var b = p[1];

I guess I don't understand Math.Net, any help with this would be great. 我想我听不懂Math.Net,这方面的任何帮助都会很棒。 Basically I have multiple x and a single y and need to get the coefficient data from them. 基本上,我有多个x和一个y,需要从它们获取系数数据。

From the way you've prepared your matrix (ie first column always 1), it seems to me you actually have 4 independent variables and you're looking for a simple regression with just a linear combination of all the independent variables as target function: 从准备矩阵的方式(即第一列始终为1)的角度来看,在我看来您实际上有4个自变量,并且您正在寻找一种简单的回归方法,该方法只需将所有自变量的线性组合作为目标函数即可:

y : (x1, ..., x4) -> p0 + p1*x1 + ... + p4*x4

If this is the case, just remove the line var X = ... and instead rename xdata to X , then all 5 parameters will be available in the p vector as expected. 如果是这种情况,只需删除var X = ...行,然后将xdata重命名为X ,则所有5个参数将按预期在p向量中可用。

Given the data above, you'll end up with approximately: 鉴于以上数据,您最终将获得:

y : (x1, ..., x4) -> 123.2 - 8.9*x1 + 2.8*x2 + 3.7*x3 - 4.4*x4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM