2

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html

It doesn't seem to have an option for uneven data points.

So the question is, given data [x, y] where spaces between x's are not equal,
how can I generate [x, yhat] where yhat is given by savgol_filter?

I'd like to draw line graph with [x, y] first, Then sample datapoints [x_, y_] which are evenly spaced.. Then I can apply savgol_filter to get a polynomial function for the approximation.

Then use the polynomial function to get [x, yhat] ..

eugene
  • 39,839
  • 68
  • 255
  • 489
  • 1
    How will you interpolate y onto a new grid? Presumably your data is noisy (as you are trying to filter it) so it's not clear how to interpolate. Also, the Savitzky–Golay filter returns the smoothed dataset (in this example yhat), not a polynomial function. Finally, the savgol_filter just smooths data, but depending on your application you might want to fit a curve instead? – tgpz Jan 22 '22 at 11:04
  • 1
    Instead of `savgol_filter`, you could use [`lowess`](https://www.statsmodels.org/v0.13.0/examples/notebooks/generated/lowess.html) from `statsmodels`. (See also [4.1.4.4 LOESS (aka LOWESS)](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd144.htm) and [Local regression](https://en.wikipedia.org/wiki/Local_regression).) My answer [here](https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy/28541805#28541805) includes an example that uses `lowess`. – Warren Weckesser Jan 22 '22 at 12:21

0 Answers0