Java Apache Commons getPercentile() 结果与 MS Excel 百分位数不同 [英] Java Apache Commons getPercentile() different result that MS Excel percentile

查看:17
本文介绍了Java Apache Commons getPercentile() 结果与 MS Excel 百分位数不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个算法,可以用 Apache Commons 计算一系列值(12 个值)的 percentile(85),以便稍后使用阈值进行评估决定.结果与 Excel 给出的结果相似,但不相等,有时这对我的应用程序很重要,因为使用 excel 结果没有通过阈值,而使用 Java 中的 Apache Commons Math 则可以,所以我得到不同的输出.

I have an algorithm that calculates the percentile(85) with Apache Commons of a series of values (12 values), for a later evaluation with a threshold to make a decision. The result is similar to the one given by Excel, but not equal, and sometimes this is critical for my application because with excel the result doesn't pass the threshold and with Apache Commons Math in Java it does, so I get different outputs.

这是一个例子:每 2 小时的互联网流量 (Mbps)

Here it is an example: Internet traffic (Mbps) every 2 hours

32,7076813360000000 41,2580429776000000 45,4453940200000000 48,8044409456000000 46,7462847936000000 49,8028100056000000 54,3719451144000000 41,9708134600000000 29,4371963240000000 22,4667255616000000 20,0388452248000000 28,7807757104000000

32,7076813360000000 41,2580429776000000 45,4453940200000000 48,8044409456000000 46,7462847936000000 49,8028100056000000 54,3719451144000000 41,9708134600000000 29,4371963240000000 22,4667255616000000 20,0388452248000000 28,7807757104000000

除以 1000 Mb(电缆的容量)后,我计算出职业的百分比(85):

After dividing by 1000 Mb (the capacity of the cable) I calculate the percentil(85) of the Occupation:

Excel:0,049153870117

Excel: 0,049153870117

Apache Commons Math:0.05003126676104001

Apache Commons Math: 0.05003126676104001

我发现可以使用 setPercentileImpl() 更改百分位数的实现(它不存在官方实现),但是我找不到任何示例说明如何操作这个,或者 Excel 算法(这是我被告知要实现的算法).

I have found that it is possible to change the implementation of the percentile (it does not exist an official one) with setPercentileImpl(), but I couldn't find any example of how to do this, or the Excel algorithm (which is the one I was told to achieve).

欢迎对此提供任何帮助.

Any help about this will be welcomed.

谢谢.

推荐答案

解决方案是创建一个 PercentileExcel 类,它几乎是 commons 方法中百分位数的副本,只是在如何计算上做了一些小改动位置:

The solution was creating a class PercentileExcel which is almost a copy of percentile from commons method except for a small change on how to caculate the position:

pos=(1+p*(n-1))/100;

然后您需要将此行添加到代码中,以便将新类用于百分位数:

Then you need to add this line to the code in order to use the new class for percentile:

setPercentileImpl(PercentileExcel);

这篇关于Java Apache Commons getPercentile() 结果与 MS Excel 百分位数不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆