首页 > 解决方案 > 从均值、起始值和结束值绘制偏态分布

问题描述

我有以下数据:

starting_point = 0.00000016
mean = 0.000351
end_point = 0.75

使用它来确定偏斜是否正确?

from scipy.stats import skew
skew([0.00000016, 0.000351, 0.75])

>> 0.7071062587209218

如何绘制分布以显示 python 3 中的偏态分布?

标签: pythondata-visualizationdistribution

解决方案


您已经计算了三个数据点的偏度。由于两个与第三个相比相当小,因此偏度是正的。通过数据拟合分布(尤其是只有三个点)更棘手。您可以参考拟合经验分布以获得详尽的描述。

就像一个分布可能看起来像偏斜的例子(正如你的数据所暗示的那样;我选择了一个伽马分布 - 小心:实际拟合要复杂得多,请参阅上面的答案;这只是为了显示区别):

from scipy import stats
import numpy as np
import matplotlib.pyplot as plt

starting_point = 0.00000016
mean = 0.000351
end_point = 0.75

data = [starting_point, mean, end_point]
print('skewness of data:', skew(data))

a, loc, scl = stats.gamma.fit(data)

x = np.arange(starting_point, end_point, 0.0002635)
plt.plot(x, stats.gamma.pdf(x, a, loc, scl))

plt.show()

dvals = [val for val in stats.gamma.pdf(x, a, loc, scl)]

print('skewness of distribution:', skew(dvals))

将导致不同的偏度(取平均值以及起点和终点来确定分布)。这给

skewness of data: 0.7071062587209218
skewness of distribution: 53.32916979819496

在此处输入图像描述


推荐阅读