首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache Commons Math3百分位数

Apache Commons Math3百分位数
EN

Stack Overflow用户
提问于 2015-03-07 02:46:11
回答 2查看 4.1K关注 0票数 7

我正在尝试使用Apache Commons Math3库和percentile类获取发行版中特定数字的百分位数:

https://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/descriptive/rank/Percentile.html

(我在Scala中使用它)

如果我这样做了:

new Percentile().evaluate(Array(1,2,3,4,5), 80)

然后我把4带回来。但是,我想走另一个方向,将4作为输入,并返回80作为结果,即给定数字的百分位数,而不是给定百分位数的数字。

这个类上的方法似乎都不符合或者给出我想要的结果。我是不是滥用了这个类?有没有我应该使用的其他类?

EN

回答 2

Stack Overflow用户

发布于 2015-04-23 15:57:30

您可以使用加载了基线值的EmpiricalDistribution:

代码语言:javascript
复制
@Test
public void testCalculatePercentile() {
    //given
    double[] values = new double[]{1,2,3,4,5};

    EmpiricalDistribution distribution = new EmpiricalDistribution(values.length);
    distribution.load(values);

    //when
    double percentile = distribution.cumulativeProbability(4);

    //then
    assertThat(percentile).isEqualTo(0.8);
}
票数 4
EN

Stack Overflow用户

发布于 2019-10-25 01:37:59

似乎不起作用,因为这个测试应该通过(但实际上它没有)

代码语言:javascript
复制
@Test
public void testCalculatePercentile() {
    //given
    double[] values = new double[]{2,3,3,3};

    EmpiricalDistribution distribution = new EmpiricalDistribution(values.length);
    distribution.load(values);

    //when
    double percentile = distribution.cumulativeProbability(2.7d);

    //then
    assertThat(percentile).isEqualTo(0.25);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28905568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档