How to make kdeplot robust to negative/zero values

263 views Asked by At

I have two real/float variables stored in native python lists:

x = [2.232, 2.331, 2.112...]
y = [-3.431, 2.213, -1.232...]

Notice that there are negative values. This seems to be giving the kde call some problems. I have gotten this error:

ZeroDivisionError: 0.0 cannot be raised to a negative power.

For my purposes, the plot doesn't need to be insanely accurate, so I attempted to add in a small amount ad hoc to both x and y:

x = []
for i in range(len(raw_data)):
    x.append(float(raw_data[i][1])+.000000001)

To my surprise, the error persisted. I even added a much larger amount (.1) but no progress was made with that either.

Question

Is there a more fool-proof way to ensure the kde call is implemented robust to non-zero entries? The fact that altering my data ad hoc didn't work suggests that something else may be wrong here.

Call

seaborn.kdeplot(x,y)

Error text

~\Anaconda3\lib\site-packages\statsmodels\nonparametric\bandwidths.py in bw_scott(x, kernel)
     53     A = _select_sigma(x)
     54     n = len(x)
---> 55     return 1.059 * A * n ** (-0.2)
     56 
     57 def bw_silverman(x, kernel=None):
0

There are 0 answers