我正在尝试使用 Apache Commons Math3 库和 Percentile 类获取分布中特定数字的百分位数:
(我在 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/