设为首页 收藏本站
查看: 1348|回复: 0

[经验分享] apache的math库中的回归——regression(翻译)

[复制链接]

尚未签到

发表于 2017-1-11 10:57:16 | 显示全部楼层 |阅读模式
  这个Math库,虽然不向weka那样专业的ML库,但是用户友好,易用。
  多元线性回归,协方差和相关性(皮尔逊和斯皮尔曼),分布测试(假设检验,t,卡方,G),统计。
  数学库中还包含,Cholesky,LU,SVD,QR,特征根分解,真不错。
  基本覆盖了:线代,统计,矩阵,
  最优化理论
  曲线拟合
  常微分方程
  遗传算法(GA),
  还有3维的运算。。。
  真应有尽有。


  • 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.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-326981-1-1.html 上篇帖子: StringUtil包函数(org.apache.commons.lang.StringUtil)之用法 下篇帖子: apache common 工具(怎样可以编写更少的代码)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表