gpt4 book ai didi

java - Apache Commons Math3 数字百分位数

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:27:31 24 4
gpt4 key购买 nike

我正在尝试使用 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 作为结果,即给定数字的百分位数,而不是给定百分位的数字。

此类中的所有方法似乎都不适合或无法提供我想要的结果。我在滥用类(class)吗?我应该使用其他类(class)吗?

最佳答案

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

@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);
}

关于java - Apache Commons Math3 数字百分位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com