Accord.net SimpleLinearRegression回归方法已经过时了吗?

时间:2017-10-04 13:37:31

标签: linear-regression accord.net

我刚刚开始学习accord.net,在通过一些例子时,我注意到SimpleLinearRegression上的Regress方法已经过时了。

显然我应该使用OrdinaryLeastSquares类,但我找不到任何会返回剩余平方和的东西,类似于回归方法。

我是否需要自己创建此方法?

1 个答案:

答案 0 :(得分:1)

以下是如何学习SimpleLinearRegression的完整示例,并且仍然能够像使用以前版本的框架一样计算剩余的平方和:

// This is the same data from the example available at
// http://mathbits.com/MathBits/TISection/Statistics2/logarithmic.htm

// Declare your inputs and output data
double[] inputs = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
double[] outputs = { 6, 9.5, 13, 15, 16.5, 17.5, 18.5, 19, 19.5, 19.7, 19.8 };

// Transform inputs to logarithms
double[] logx = Matrix.Log(inputs);

// Use Ordinary Least Squares to learn the regression
OrdinaryLeastSquares ols = new OrdinaryLeastSquares();

// Use OLS to learn the simple linear regression
SimpleLinearRegression lr = ols.Learn(logx, outputs);

// Compute predicted values for inputs
double[] predicted = lr.Transform(logx);

// Get an expression representing the learned regression model
// We just have to remember that 'x' will actually mean 'log(x)'
string result = lr.ToString("N4", CultureInfo.InvariantCulture);

// Result will be "y(x) = 6.1082x + 6.0993"

// The mean squared error between the expected and the predicted is
double error = new SquareLoss(outputs).Loss(predicted); // 0.261454

此示例中的最后一行应该是您最感兴趣的一行。如您所见,现在可以使用SquareLoss class计算.Regress方法预先返回的剩余平方和。此方法的优点是,您现在应该能够计算对您最重要的最合适的指标,例如ZeroOneLossEuclidean lossHamming loss

无论如何,我只是想重申一下,框架中标记为Obsolete的任何方法都不会很快停止工作。它们被标记为过时,意味着在使用这些方法时不支持新功能,但如果您使用了其中任何一种方法,您的应用程序将不会停止工作。