7

While I was trying to plot a seaborn kdeplot, there was an error:

UserWarning: Dataset has 0 variance; skipping density estimate

I don't understand what this means. I also found that if I created a distplot for the x-axis and y-axis, there was no kde curve as well.

with sns.axes_style('white'):
    plot = sns.jointplot(x='Latitude', y='Longitude', data=df, kind="kde", space=0.7, bw_adjust=3)

How can I fix this problem?

tdy
  • 36,675
  • 19
  • 86
  • 83
Xiang
  • 139
  • 1
  • 2
  • 8
  • 1
    Without seeing the data, it is hard to guess. Maybe all values are strings instead of numbers? How does the plot look like? – JohanC Oct 31 '20 at 23:20
  • is your data containing any values in columns you're trying to visualize? The error message just says there is no variance in the dataset, which may point to several possible explanations: no data, the same value in the column... – Oskar_U Oct 31 '20 at 23:21
  • Sorry, the values are float. Indeed, there are many repeated values in the Latitude and Longitude columns. – Xiang Oct 31 '20 at 23:40
  • 1
    If I change kind='hex', I can see the distribution of data with histograms on the marginal sides. – Xiang Oct 31 '20 at 23:42
  • 1
    This seems related to https://github.com/mwaskom/seaborn/issues/2294 the underlying 'issue' is that math.isclose is being used. Can you compute your variance and post it? – hadron Jan 18 '21 at 01:44
  • can you share the data in df plesae. without that i think everyone is guessing what the error message is – Joe Ferndz Feb 22 '21 at 01:19
  • @Xiang what is the variance of your dataset? Also, what do you get when you run `math.isclose(np.var(df), 0)` ? – Gonçalo Peres May 05 '21 at 08:46

2 Answers2

1

Ok, I have a bizarre suggestion.

If you get this warning with data that shouldn't have variance = 0, check your floats format. My plots were working fine. Then, I decided to use float16 for my numeric columns to save memory, and the same code stopped working.

Somehow, having less decimals kills the variance calculation, so, ensure your floats have enough: df["yourCol"].astype("float64").

Jota92
  • 21
  • 1
  • 4
0

1st that is a warning and not an error, the reason for that is some variable either 'Latitude', 'Longitude' must be (a constant number)(not changing)

Edit: so you can give the DataFrame also so that we can see what is the exact problem

user16714199
  • 228
  • 6
  • 19