seaborn: Selected KDE bandwidth is 0. Cannot estimate density

后端 未结 5 670
北恋
北恋 2021-01-04 18:32
import pandas as pd
import seaborn as sns

ser_test = pd.Series([1,0,1,4,6,0,6,5,1,3,2,5,1])
sns.kdeplot(ser_test, cumulative=True)

The above code g

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 19:06

    What's going on here is that Seaborn (or rather, the library it relies on to calculate the KDE - scipy or statsmodels) isn't managing to figure out the "bandwidth", a scaling parameter used in the calculation. You can pass it manually. I played with a few values and found 1.5 gave a graph at the same scale as your previous:

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

    See also here. Worth installing statsmodels if you don't have it.

提交回复
热议问题