我刚刚开始学习accord.net,并通过一些例子,我注意到SimpleLinearRegression上的Regress方法已过时。Accord.net SimpleLinearRegression的回归方法已过时?
显然我应该使用OrdinaryLeastSquares类,但是我找不到任何会返回残差平方和的东西,类似于Regress方法。
我是否需要自己创建此方法?
我刚刚开始学习accord.net,并通过一些例子,我注意到SimpleLinearRegression上的Regress方法已过时。Accord.net SimpleLinearRegression的回归方法已过时?
显然我应该使用OrdinaryLeastSquares类,但是我找不到任何会返回残差平方和的东西,类似于Regress方法。
我是否需要自己创建此方法?
这里是如何学习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方法返回的残差平方和。这种方法的优点是,现在您应该能够计算出最适合您的最合适的指标,如ZeroOneLoss或Euclidean loss或Hamming loss。
无论如何,我只是想重申,在框架中标记为Obsolete的任何方法都不会很快停止工作。它们被标记为废弃的含义,即在使用这些方法时不会支持新功能,但是如果您使用其中的任何方法,则您的应用程序不会停止工作。
尊敬的@Cesar,我有一个像[1000,100,100,100,100,100] 阵列我怎样才能预测下一个数字使用协议? – HamidEbr
看看第二个例子[这里](http://accord-framework.net/docs/html/T_Accord_Statistics_Models_Regression_Linear_SimpleLinearRegression.htm):'SquareLoss'。 – jsanalytics