RuntimeWarning: overflow encountered in long_scalars   h = 12.0 / (totaln * (totaln + 1)) * ssbn - 3

描述:

使用stats.kruskal()计算Kruskal-Wallis 秩和检验,数据量2042000条,所以计算的时候,警告内存溢出。

RuntimeWarning: overflow encountered in long_scalars   
h = 12.0 / (totaln * (totaln + 1)) * ssbn - 3

问题就出在 h = 12.0 / (totaln * (totaln + 1)) * ssbn - 3这一行代码,
(totaln * (totaln + 1)),计算的结果太大了,只需要更改运算顺序即可

h = 12.0 / (totaln * (totaln + 1)) * ssbn - 3 * (totaln + 1)  # 原代码

h = (ssbn / totaln) / (totaln + 1) * 12.0 - 3 * (totaln + 1)  # 修改了运算顺序

将原代码注释掉,更改为h = (ssbn / totaln) / (totaln + 1) * 12.0 - 3 * (totaln + 1)即可解决问题。

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页