question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lmplot fails with lowess=True

See original GitHub issue

Dear Seaborn developpers,

I’m trying a simple lmplot that fails as follows:

In [22]: sns.lmplot(data=go, x="states", y="rate", lowess=True)
/home/franck/.local/lib/python3.5/site-packages/numpy/lib/function_base.py:4016: RuntimeWarning: Invalid value encountered in median
  r = func(a, **kwargs)
/home/franck/.local/lib/python3.5/site-packages/statsmodels/nonparametric/smoothers_lowess.py:165: RuntimeWarning: invalid value encountered in greater_equal
  res = _lowess(y, x, frac=frac, it=it, delta=delta)
Out[22]: <seaborn.axisgrid.FacetGrid at 0x7ff15d5b97f0>

The data is not something complicated or strange, here is the CSV: go.csv.gz As a result, I got the scatter plot but not the smoothed curve: figure_1

I have many other similar data sets that cause no problem, I’ve just isolated this particular one that fails. I’m working with Python 3.5.2, Seaborn 0.8.1, Numpy 1.13.3, and Statsmodel 0.8.0.

Any help will be very wellcome, thanks in advance! Franck

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Dec 6, 2017

Yep, I think issue is what’s happening here. I can’t explain exactly what statsmodels is doing, but it makes sense. “lowess” stands for “locally weighted smoothing”. There is at least one segment in your dataset where for a reasonable definition of “local”, there is nothing to smooth.

I don’t think seaborn should do anything here. Raising would be annoying if you’re trying to draw a big facet grid where one or two subsets has a failing lowess. A warning would be good, but statsmodels is in the better position to give an informative warning about exactly what’s happening. All seaborn can do really is say that “something” has gone wrong, but that’s already obvious from the lack of a line on the plot.

0reactions
fpomcommented, Dec 6, 2017

But I don’t know how you call it… 😃 I’ve patched around the call res = _lowess(y, x, frac=frac, it=it, delta=delta) to observe parameters and return value. It yields:

y = array([ 6075.        ,  6075.        ,  4860.        ,  6075.        ,
        4050.        ,  6075.        ,  4050.        ,  4860.        ,
        6075.        ,  6075.        ,  6075.        ,  2430.        ,
        4860.        ,  2082.85714286,  2209.09090909,  1487.75510204,
        1918.42105263,  1458.        ,  2144.11764706,  1487.75510204,
        2025.        ,  2082.85714286,  2082.85714286,  2209.09090909,
        2209.09090909,  1375.47169811,   557.90816327,   523.20574163,
         571.01827676,   609.19220056,   609.19220056,   533.41463415,
         571.01827676,   494.79638009,   562.21079692,   525.72115385,
         609.19220056,   457.53138075])
x = array([  243.,   243.,   243.,   243.,   243.,   243.,   243.,   243.,
         243.,   243.,   243.,   243.,   243.,   729.,   729.,   729.,
         729.,   729.,   729.,   729.,   729.,   729.,   729.,   729.,
         729.,   729.,  2187.,  2187.,  2187.,  2187.,  2187.,  2187.,
        2187.,  2187.,  2187.,  2187.,  2187.,  2187.])
frac = 0.6666666666666666
it = 3
delta = 0.0
/home/franck/.local/lib/python3.5/site-packages/numpy/lib/function_base.py:4016: RuntimeWarning: Invalid value encountered in median
  r = func(a, **kwargs)
/home/franck/.local/lib/python3.5/site-packages/statsmodels/nonparametric/smoothers_lowess.py:171: RuntimeWarning: invalid value encountered in greater_equal
  res = _lowess(y, x, frac=frac, it=it, delta=delta)
res = array([[  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  243.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [  729.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan],
       [ 2187.,    nan]])

Can you confirm this is a bug in statsmodels?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Markers in seaborn lmplot - python - Stack Overflow
The markers argument in lmplot() requires a single entry for each level ... fit_reg=False, hue='z', lowess=True, scatter_kws={'alpha': 0.5}, ...
Read more >
seaborn.lmplot — seaborn 0.12.1 documentation - PyData |
seaborn.lmplot# ... Plot data and regression model fits across a FacetGrid. This function combines regplot() and FacetGrid . It is intended as a...
Read more >
Lab 9 — Stat 159/259 - Reproducible and Collaborative Data ...
The lmplot function will plot a scatter plot of the data and fit and visualize a linear model on top of it. Let's...
Read more >
Linear regression diagnostics in Python - Jan Kirenz
Non-linearity of the response-predictor relationship; Non-constant variance of error terms (heteroscedasticity); Non-normally distributed errors ...
Read more >
Linear models with quantitative data - | notebook.community
For instance, it is common to plot the *standard error* of an estimate, which corresponds to the 68% confidence interval. In [ ]:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found