其他分享
首页 > 其他分享> > 成功解决RuntimeError: Selected KDE bandwidth is 0. Cannot estiamte density

成功解决RuntimeError: Selected KDE bandwidth is 0. Cannot estiamte density

作者:互联网

成功解决RuntimeError: Selected KDE bandwidth is 0. Cannot estiamte density

 

 

 

解决问题

RuntimeError: Selected KDE bandwidth is 0. Cannot estiamte density.


 

解决思路

运行时错误:选择的KDE带宽为0。不能estiamte密度。

 

 

 

解决方法

 

出现此bug,是因为Seaborn库(它依赖的scipy或statmodels库来计算kde)没有办法计算出“bandwidth”,kdeplot函数中的bw参数,是一个缩放参数,当然也可以自定义。

 

1、重新定义bw参数

sns.kdeplot(ser_test, cumulative=True, bw=1.5)

 

2、调试

try:
    sns.distplot(df)
except RuntimeError as re:
    if str(re).startswith("Selected KDE bandwidth is 0. Cannot estimate density."):
        sns.distplot(df, kde_kws={'bw': 0.1})
    else:
        raise re

​

 

参考文章https://stackoverflow.com/questions/60596102/seaborn-selected-kde-bandwidth-is-0-cannot-estimate-density

 

 

 

 

 

标签:density,KDE,RuntimeError,Selected,bandwidth,Cannot
来源: https://blog.51cto.com/u_14217737/2908454