Accord.NET 中已知固定截距的线性回归

Linear Regression with a known fixed intercept in Accord.NET

我使用Accord.NET根据此页面计算线性回归的斜率和截距http://accord-framework.net/docs/html/T_Accord_Statistics_Models_Regression_Linear_SimpleLinearRegression.htm

我想设置一个固定的拦截值,这样 Accord 将只预测斜率。我可以在 Accord.NET 做那件事吗?

Dim inp(10), opt(10) As Double
inp = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
opt = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}

Dim ols As New OrdinaryLeastSquares
Dim reg As New SimpleLinearRegression

reg.Intercept = 4 'no effect, how can we set the intercept value?
reg = ols.Learn(inp, opt)

Dim hsl As String
hsl = "y=" + reg.Slope.ToString + "X+" + reg.Intercept.ToString

设置ols.UseIntercept = False,给每个opt值加上想要的截距值,运行ols.Learn()。结果 Slope 将根据您想要的截距进行计算。