首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Accord.net SimpleLinearRegression回归方法过时了吗?

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

Stack Overflow用户
提问于 2017-10-04 21:37:31
回答 1查看 384关注 0票数 0

我刚刚开始学习accord.net,在浏览一些示例时,我注意到SimpleLinearRegression上的回归方法已经过时了。

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

我需要自己创建这个方法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-10-24 04:42:51

下面是一个完整的例子,说明如何学习SimpleLinearRegression,并仍然能够像使用以前版本的框架一样计算残差平方和:

代码语言:javascript
复制
// 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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46566371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档