1

有谁知道如何使用 Python 单独从分箱数据计算分布的峰度?

我有一个分布的直方图,但没有原始数据。有两列;一个带有 bin 编号,一个带有计数编号。我需要计算分布的峰度。

如果我有原始数据,我可以使用 scipy 函数来计算峰度。我在本文档中看不到任何使用分箱数据进行计算的内容。 https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kurtosis.html

scipy 的 binned statistics 选项允许您计算 bin 内的峰度,但仅使用原始数据且仅在 bin 内。 https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.stats.binned_statistic.html

编辑:示例数据。我可以尝试从中重新采样以创建我自己的虚拟原始数据,但我每天要运行大约 140k 的这些数据,并且希望有一些内置的东西。

Index,Bin,Count
 0, 730, 30
 1, 735, 45
 2, 740, 41
 3, 745, 62
 4, 750, 80
 5, 755, 96
 6, 760, 94
 7, 765, 90
 8, 770, 103
 9, 775, 96
10, 780, 95
11, 785, 109
12, 790, 102
13, 795, 99
14, 800, 93
15, 805, 101
16, 810, 109
17, 815, 98
18, 820, 89
19, 825, 62
20, 830, 71
21, 835, 69
22, 840, 58
23, 845, 50
24, 850, 42
4

1 回答 1

2

您可以直接计算统计数据。如果x是您的 bin 编号,并且y是每个 bin 的计数,则 的预期值f(x)等于np.sum(y*f(x))/np.sum(y)。我们可以使用它将峰度公式转换为以下代码:

total = np.sum(y)
mean = np.sum(y * x) / total
variance = np.sum(y * (x - mean)**2) / total
kurtosis = np.sum(y * (x - mean)**4) / (variance**2 * total)

请注意,峰度和过度峰度不是一回事。

于 2019-01-29T22:57:06.530 回答