While using pairplot using seaborn package, I am getting error as "Selected KDE bandwidth is 0. Cannot estiamte density". Can someone please help on this?

While using pairplot using seaborn package, I am getting error as “Selected KDE bandwidth is 0. Cannot estiamte density”. Can someone please help on this?

Uhh…can you help with something more like a snapshot(which would be much better),or help me with the command that you used for pairplot!!

I guess what is happening here is that seaborn is not able to calculate the bandwidth from the given data.Just to be sure, can you use the same lines of code on some other dataset and see if you get the same error.
Incase, you don’t get the error back, try to manually pass the bandwidth to this problem and see if you get the results.

Hi Yash,

Thanks for replying … I was using below code…

sns.pairplot(mpg_df_attr, diag_kind=‘kde’)

The plot is coming but only for diagonal elements. would this help you to advise?

Thanks for replying.

How to pass manually the band with? can you please advise? My command is

sns.pairplot(mpg_df_attr, diag_kind=‘kde’)


Ohkk,code line seems fine btw never remember having faced such a problem & have worked on the mpg dataset,although you mentioned now that plot is appearing only for diagonal elements which means you’re kde is solved since kde appears for diagonal elements .About all those non-diagonal elements they would be on a scatter plot ,so I believe some sort of scaling or normalization is being done by you plus check if the mpg_df_attr has only scaled independent variables? If so then check with the entire dataset which has both independent & target variables & then try a seaborn plot plus check for the null values in each of your columns as well(specially in this mpg_df_attr that you provided to the seaborn command, I doubt the values have been nullified). Let me know if that helps!!

Q1. are you getting this error when including only numerical columns ?
Q2. are you getting this error only when you are mentioning “hue” (categorical col) for a big data set?

Method #1. since it is not able to estimate the density, you can assign the bw parameter of kde and check.

Method #2. confirm your pair plot is working at least for numerical columns
sns.pairplot(df.loc[:,[‘Age’,‘Experience’,‘Income’,‘ZIP Code’]])

Method #3. you can try with other plot methods. eg. kdeplot, distplot, pair grid, facet grid, etc.,
g = g.map_diag(plt.hist,histtype=“step”, linewidth=3)
g = g.map_offdiag(plt.scatter)
g = g.add_legend()

Method #4. If you are still getting the same error with simple dataset, you need to check all versions, and re-install if required (seaborn, statsmodels, jupyter notebook etc.,)

let me know if it works for you.