Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Lowess extrapolation missing output values. #7337

Open
tprodanov opened this issue Feb 20, 2021 · 0 comments · May be fixed by #9220 or #9221
Open

BUG: Lowess extrapolation missing output values. #7337

tprodanov opened this issue Feb 20, 2021 · 0 comments · May be fixed by #9220 or #9221

Comments

@tprodanov
Copy link

Bug description

Suppose input values are defined on [5, 14], Then if you use lowess and use xvals to get values on a bigger range of Xs (for example [0, 19]), the output may contain undefined values even on the input range of Xs. Additionally, different frac values produce different behaviours that are not obvious.

In the last example, output is undefined even if you use the same output X values as input X values.

Code example

from statsmodels.nonparametric.smoothers_lowess import lowess
import numpy as np
import sys

np.set_printoptions(precision=6, linewidth=sys.maxsize, suppress=True, threshold=sys.maxsize)

x = np.arange(5, 15).astype(np.float)
y = np.arange(5, 15).astype(np.float)
out_x = np.arange(0, 20).astype(np.float)

lowess(y, x, xvals=out_x, frac=0.6)
# array([-0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19.])

lowess(y, x, xvals=out_x, frac=0.5)
# array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 11., nan, nan, nan, nan, nan, nan, nan, nan])

lowess(y, x, xvals=out_x, frac=0.4)
# array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19.])

lowess(y, x, xvals=out_x, frac=0.3)
# array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

lowess(y, x, xvals=x, frac=0.5)
# array([ 5.,  6.,  7.,  8.,  9., 10., 11., nan, nan, nan])

Expected output

Ideally, lowess output should be defined at least on the range of input Xs.

Also, values do not become NaNs gradually (for example undefined below some frac value and defined above).
Because of that it looks like a bug and not like an expected behaviour.

Output of import statsmodels.api as sm; sm.show_versions()


INSTALLED VERSIONS
------------------
Python: 3.6.10.final.0
OS: Linux 5.4.95-1-MANJARO #1 SMP PREEMPT Thu Feb 4 00:38:02 UTC 2021 x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

statsmodels
===========

Installed: 0.12.2 (/home/timofey/.miniconda3/lib/python3.6/site-packages/statsmodels)

Required Dependencies
=====================

cython: 0.29.21 (/home/timofey/.miniconda3/lib/python3.6/site-packages/Cython)
numpy: 1.19.1 (/home/timofey/.miniconda3/lib/python3.6/site-packages/numpy)
scipy: 1.5.2 (/home/timofey/.miniconda3/lib/python3.6/site-packages/scipy)
pandas: 1.1.5 (/home/timofey/.miniconda3/lib/python3.6/site-packages/pandas)
    dateutil: 2.8.1 (/home/timofey/.miniconda3/lib/python3.6/site-packages/dateutil)
patsy: 0.5.1 (/home/timofey/.miniconda3/lib/python3.6/site-packages/patsy)

Optional Dependencies
=====================

matplotlib: Not installed
cvxopt: Not installed
joblib: Not installed

Developer Tools
================

IPython: 7.16.1 (/home/timofey/.miniconda3/lib/python3.6/site-packages/IPython)
    jinja2: 2.11.3 (/home/timofey/.miniconda3/lib/python3.6/site-packages/jinja2)
sphinx: Not installed
    pygments: 2.7.4 (/home/timofey/.miniconda3/lib/python3.6/site-packages/pygments)
pytest: Not installed
virtualenv: 16.7.5 (/home/timofey/.miniconda3/lib/python3.6/site-packages)
@tprodanov tprodanov changed the title Lowess extrapolation missing output values. BUG: Lowess extrapolation missing output values. Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant