Python数据分析使用fowlkers_mallows_score()函数发生警告、结果不在[0,1]内是啥情况啊?

相关代码:

from sklearn.metrics import fowlkes_mallows_score
fmi_score=fowlkes_mallows_score(bidding_target_train,kmeans.labels_)
fmi_score

警告内容:
E:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\cluster\supervised.py:859: RuntimeWarning: overflow encountered in int_scalars
return tk / np.sqrt(pk * qk) if tk != 0. else 0.

img

分母为0吗?聚类算法的参数发来瞅瞅

这个警告使用 fowlkes_mallows_score 函数时遇到了数值上溢的问题,这可能导致函数结果不精确或超出预期的范围。溢出可以发生在分子或分母上,这里的警告提示出现在计算适度特征值(Moderate Purity)时,即在计算 FMI 分数时。如果函数结果不在 [0,1] 的范围之间,可能是由于这个数值溢出所导致的。

尝试使用以下方法解决这个问题:

  • 尝试使用双精度浮点数(double-precision floating-point)存储数据;
  • 避免使用非常大或非常小的值进行计算,这些值可能会引起溢出,还可能会在计算过程中被四舍五入;
  • 考虑使用更高精度的数值类型或库来进行计算,如 Decimal