微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 使用Math.NET约束的线性回归

我正在使用Math.NET进行简单的线性回归.

我在下面提供了一个通用代码示例.作为此示例的替代,可以使用Fit类进行简单的线性回归.

我还想要的是指定额外的约束,例如固定的y轴截距或强制拟合通过固定点运行,例如,(2,2).如何在Math.NET中实现这一目标?

var xdata = new double[] { 10,20,30 };
var ydata = new double[] { 15,25 };

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];

解决方法

您可以修改数据集以反映约束,然后使用标准的math.Net线性回归

if (x0,y0) is the point through which the regression line must pass,
fit the model y−y0=β(x−x0)+ε,i.e.,a linear regression with “no
intercept” on a translated data set.

见这里:https://stats.stackexchange.com/questions/12484/constrained-linear-regression-through-a-specified-point

在这里http://en.wikipedia.org/wiki/Linear_least_squares_(mathematics)#Constrained_linear_least_squares

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐