我正在尝试使用Apache Commons Math3库和percentile类获取发行版中特定数字的百分位数:
(我在Scala中使用它)
如果我这样做了:
new Percentile().evaluate(Array(1,2,3,4,5), 80)
然后我把4带回来。但是,我想走另一个方向,将4作为输入,并返回80作为结果,即给定数字的百分位数,而不是给定百分位数的数字。
这个类上的方法似乎都不符合或者给出我想要的结果。我是不是滥用了这个类?有没有我应该使用的其他类?
发布于 2015-04-23 15:57:30
您可以使用加载了基线值的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);
}发布于 2019-10-25 01:37:59
似乎不起作用,因为这个测试应该通过(但实际上它没有)
@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);
}https://stackoverflow.com/questions/28905568
复制相似问题