Simple Regression 用于使用 Apache Maths 在 Java 中计算斜率。

huangapple go评论70阅读模式
英文:

Simple Regression for calculating slope using apache maths in Java

问题

我正在尝试使用简单回归计算斜率。
这是我的两个数组:

XLIST [9.570915222167969,7.601962566375732,6.5179524421691895,5.71270227432251,5.095747947692871,4.610823631286621,4.221418380737305,3.902977705001831,3.6384739875793457,3.4157819747924805]
YList [10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0]

然而,斜率为7.9192681940221545,如下所示:

double[][] pqr={ArrayUtils.toPrimitive(xList.toArray(new Double[0])),ArrayUtils.toPrimitive(yList.toArray(new Double[0]))};
simpleRegression.addData(pqr);
System.out.println(" The slope" + simpleRegression.getSlope());

然而,我能够看到在Excel中的斜率存在差异,即-0.6132。

我不确定我在哪里出错了。

在这方面的任何信息都将有助于。

英文:

I am trying to calculate the slope using simple regression.
Here is my two Arrays:

XLIST  [9.570915222167969 , 7.601962566375732 , 6.5179524421691895 , 5.71270227432251 , 5.095747947692871 , 4.610823631286621 , 4.221418380737305 , 3.902977705001831 , 3.6384739875793457 , 3.4157819747924805]
YList [10.0 , 11.0 , 12.0 , 13.0 , 14.0 , 15.0 , 16.0 , 17.0 , 18.0 , 19.0]

However, the slope is 7.9192681940221545 using below:

double[][] pqr={ArrayUtils.toPrimitive(xList.toArray(new Double[0])),ArrayUtils.toPrimitive(yList.toArray(new Double[0]))};
simpleRegression.addData(pqr);
System.out.println(" The slope" + simpleRegression.getSlope());

However, I am able to see a discrepancy in the excel slope, i.e., -0.6132.

I am not sure where am I doing the mistake.

Any info in this regard will be helpful.

答案1

得分: 1

你将数据错误地传递给了addData(double[][])方法。

addData方法假定你传递的是一个包含x-y对的数组。而实际上,你传递的是两个分开的x值和y值数组。你可以创建一个正确形状的数组,或者使用其他可用的方法传递数据。例如:

for (int i=0; i<xList.size(); i++)
    simpleRegression.addData(xList.get(i), yList.get(i));
英文:

You're passing the data wrong to the addData(double[][]) method.

The addData method assumes that you're passing in an array of x-y pairs. Instead your passing in x values and y values in two separate arrays. You can either create an array of the right shape, or pass the data in with the other methods available. For example

for (int i=0; i&lt;xList.size(); i++)
    simpleRegression.addData(xList.get(i), yList.get(i));

</details>



huangapple
  • 本文由 发表于 2020年8月3日 06:51:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63221760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定