python - 从均值、起始值和结束值绘制偏态分布
问题描述
我有以下数据:
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 中的偏态分布?
解决方案
您已经计算了三个数据点的偏度。由于两个与第三个相比相当小,因此偏度是正的。通过数据拟合分布(尤其是只有三个点)更棘手。您可以参考拟合经验分布以获得详尽的描述。
就像一个分布可能看起来像偏斜的例子(正如你的数据所暗示的那样;我选择了一个伽马分布 - 小心:实际拟合要复杂得多,请参阅上面的答案;这只是为了显示区别):
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
推荐阅读
- neo4j - neo4j cypher shell:输入分号无效
- copy - 如何使用临时堆栈复制堆栈?
- python - 点云上的目标检测
- c# - 克服从 .NET 5 迁移到 6 时检测到的降级问题
- python - 如何防止 Geopy 出现此速率限制器错误?
- python - 如何将双引号添加到具有 JSON 结构的字符串的元素数组?
- python - 访问从 pygame.sprite.spritecollide ( Pygame 2, Python 3 ) 返回的列表中对象(精灵)的属性
- asp.net-core - 如何从 Angular 应用程序调用受保护的 Web api
- python - 如何格式化 JSON?
- javascript - 使用 React Bootstrap Navigation 出现 Headless Wordpress 子菜单的问题