2017-10-04 51 views
0

我剛剛開始學習accord.net,並通過一些例子,我注意到SimpleLinearRegression上的Regress方法已過時。Accord.net SimpleLinearRegression的迴歸方法已過時?

顯然我應該使用OrdinaryLeastSquares類,但是我找不到任何會返回殘差平方和的東西,類似於Regress方法。

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

+1

看看第二個例子[這裏](http://accord-framework.net/docs/html/T_Accord_Statistics_Models_Regression_Linear_SimpleLinearRegression.htm):'SquareLoss'。 – jsanalytics

回答

0

這裏是如何學習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的任何方法都不會很快停止工作。它們被標記爲廢棄的含義,即在使用這些方法時不會支持新功能,但是如果您使用其中的任何方法,則您的應用程序不會停止工作。

+0

尊敬的@Cesar,我有一個像[1000,100,100,100,100,100] 陣列我怎樣才能預測下一個數字使用協議? – HamidEbr