【问题标题】:Mapping each value in a list to its percentile of a different distribution将列表中的每个值映射到不同分布的百分位数
【发布时间】:2018-05-15 22:01:40
【问题描述】:

我有一个列表 scores 和一个列表 distribution。我需要将scores 中的每个分数映射到distribution 中对应的百分位数。

例子:

distribution=[4,10,3,5,1]
scores = [1,6,11]

运算结果应该是[20,80,100]

Map each list value to its corresponding percentile 有人问过这个类似的问题,但在我的情况下,使用 scipy.stats.rankdata 是不可能的,因为我需要找到每个项目相对于不同分布的百分位数。

解决它的自然方法是[scipy.stats.percentileofscore(distribution,s) for s in scores],但是当scoresdistribution 很大(每个长度大于约10,000)时,这非常慢。

有什么方法可以大大加快速度吗?我试过先对通讯组列表进行排序,然后进行标准搜索,但最坏的情况仍然很糟糕。

【问题讨论】:

    标签: python statistics distribution


    【解决方案1】:

    查看binning:使用您的参考分布作为数据集,并将分数作为 bin 边界。结果将是分布中的值箱,例如:

    [ [1], [4, 3, 5], [10] ]

    您现在取每个 bin 的长度(一些 binning 包与 binning 列表一起返回)并除以总分布人口;这为您提供了递增的百分位数:

    [0.20, 0.60, 0.20]
    

    从这里开始,累积和是微不足道的

    [0.20, 0.80, 1.0]
    

    这会让你感动吗?

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 2012-09-07
      • 2021-12-03
      • 2019-05-28
      • 1970-01-01
      • 2013-12-27
      • 2021-02-21
      • 1970-01-01
      相关资源
      最近更新 更多