当前位置:首页 > 开发 > 开源软件 > 正文

apache的math库中的回归——regression(翻译)

发表于: 2013-08-23   作者:lvdccyb   来源:转载   浏览:
摘要: 这个Math库,虽然不向weka那样专业的ML库,但是用户友好,易用。 多元线性回归,协方差和相关性(皮尔逊和斯皮尔曼),分布测试(假设检验,t,卡方,G),统计。   数学库中还包含,Cholesky,LU,SVD,QR,特征根分解,真不错。   基本覆盖了:线代,统计,矩阵, 最优化理论 曲线拟合 常微分方程 遗传算法(GA), 还有3维的运算。。。

这个Math库,虽然不向weka那样专业的ML库,但是用户友好,易用。

多元线性回归,协方差和相关性(皮尔逊和斯皮尔曼),分布测试(假设检验,t,卡方,G),统计。

 

数学库中还包含,Cholesky,LU,SVD,QR,特征根分解,真不错。

 

基本覆盖了:线代,统计,矩阵,

最优化理论

曲线拟合

常微分方程

遗传算法(GA),

还有3维的运算。。。

真应有尽有。

 

  1. Frequency

频率分布统计,

支持Integer,Float等(只要实现Comparable的任何类);

Count string frequencies计算字符串的频率Using case-sensitive comparison, alpha sort order (natural comparator):大小写敏感,而且以字母顺序排序(默认比较器)

Frequency f =newFrequency();
f.addValue("one");
f.addValue("One");
f.addValue("oNe");
f.addValue("Z");System.out.println(f.getCount("one"));// displays 1System.out.println(f.getCumPct("Z"));  // displays 0.5System.out.println(f.getCumPct("Ot"));// displays 0.25
          

 

Using case-insensitive comparator:大小写不敏感

Frequency f = new Frequency(String.CASE_INSENSITIVE_ORDER);
f.addValue("one");
f.addValue("One");
f.addValue("oNe");
f.addValue("Z");
System.out.println(f.getCount("one"));  // displays 3
System.out.println(f.getCumPct("z"));  // displays 1

 

1.5 Multiple linear regression 多元线性回归

OLSMultipleLinearRegression and GLSMultipleLinearRegression provide least squares regression to fit the linear model:

Y=X*b+u

where Y is an n-vector regressand, X is a [n,k] matrix whose k columns are called regressors, b is k-vector of regression parameters and u is an n-vector of error terms or residuals.

OLSMultipleLinearRegression provides Ordinary Least Squares Regression, and  implements Generalized Least Squares. See the javadoc for these classes for details on the algorithms and forumlas used.

OLSMultipleLinearRegression 和 GLSMultipleLinearRegression 提供最小方差线性回归模型:

Y=X*b+u

其中,Y是一个n维的回归变量,X是m*k的矩阵,其中k列称为自变量,b是长度为k的回归参数向量。u则是误差或者残余方差。

OLSMultipleLinearRegression 提供一个常见的最小方差回归,GLSMultipleLinearRegression

Data for OLS models can be loaded in a single double[] array, consisting of concatenated rows of data, each containing the regressand (Y) value, followed by regressor values; or using a double[][] array with rows corresponding to observations. GLS models also require a double[][] array representing the covariance matrix of the error terms.

OLS模型数据可以以一维double数组加载,数组以行数据串联,每行数据包含回归方程的独立自变量和 回归方程的因变量(Y),或者二维double数组,相应的每行一组观察值。GLS模型也需要一个误差的协方差矩阵的二维的double[][]数组

See AbstractMultipleLinearRegression#newSampleData(double[],int,int)OLSMultipleLinearRegression#newSampleData(double[], double[][]) andGLSMultipleLinearRegression#newSampleData(double[],double[][],double[][]) for details.

 

 

 

 

Usage Notes:

  • Data are validated when invoking any of the newSample, newX, newY or newCovariance methods and IllegalArgumentException is thrown when input data arrays do not have matching dimensions or do not contain sufficient data to estimate the model.
  • By default, regression models are estimated with intercept terms. In the notation above, this implies that the X matrix contains an initial row identically equal to 1. X data supplied to the newX or newSample methods should not include this column - the data loading methods will create it automatically. To estimate a model without an intercept term, set the noIntercept property to true.

Here are some examples.

OLS regression



Instantiate an OLS regression object and load a dataset:
OLSMultipleLinearRegression regression =newOLSMultipleLinearRegression();double[] y =newdouble[]{11.0,12.0,13.0,14.0,15.0,16.0};double[] x =newdouble[6][];
x[0]=newdouble[]{0,0,0,0,0};
x[1]=newdouble[]{2.0,0,0,0,0};
x[2]=newdouble[]{0,3.0,0,0,0};
x[3]=newdouble[]{0,0,4.0,0,0};
x[4]=newdouble[]{0,0,0,5.0,0};
x[5]=newdouble[]{0,0,0,0,6.0};          
regression.newSample(y, x);
          
Get regression parameters and diagnostics:
double[] beta = regression.estimateRegressionParameters();     //beta值

double[] residuals = regression.estimateResiduals();残余方差double[][] parametersVariance = regression.estimateRegressionParametersVariance();double regressandVariance = regression.estimateRegressandVariance();double rSquared = regression.calculateRSquared();//R回归方差double sigma = regression.estimateRegressionStandardError();//标准差
         
GLS regression



Instantiate a GLS regression object and load a dataset:
GLSMultipleLinearRegression regression =newGLSMultipleLinearRegression();double[] y =newdouble[]{11.0,12.0,13.0,14.0,15.0,16.0};double[] x =newdouble[6][];
x[0]=newdouble[]{0,0,0,0,0};
x[1]=newdouble[]{2.0,0,0,0,0};
x[2]=newdouble[]{0,3.0,0,0,0};
x[3]=newdouble[]{0,0,4.0,0,0};
x[4]=newdouble[]{0,0,0,5.0,0};
x[5]=newdouble[]{0,0,0,0,6.0};          
double[][] omega =newdouble[6][];
omega[0]=newdouble[]{1.1,0,0,0,0,0};
omega[1]=newdouble[]{0,2.2,0,0,0,0};
omega[2]=newdouble[]{0,0,3.3,0,0,0};
omega[3]=newdouble[]{0,0,0,4.4,0,0};
omega[4]=newdouble[]{0,0,0,0,5.5,0};
omega[5]=newdouble[]{0,0,0,0,0,6.6};
regression.newSampleData(y, x, omega); //GLS模型需要提供OMEGA

1.7 Covariance and correlation协方差和相关性

The org.apache.commons.math3.stat.correlation package computes covariances and correlations for pairs of arrays or columns of a matrix. Covariance computes covariances, PearsonsCorrelation provides Pearson's Product-Moment correlation coefficients and SpearmansCorrelation computes Spearman's rank correlation.

apache的math库中的回归——regression(翻译)

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

推荐文章
编辑推荐
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号