I'm attempting to fit a cubic spline to a time-series using scipy's interpolate.splrep
. However, I can't work out how to determine a valid smoothing condition without manually adjusting it by eye. It seems like there should be a way to calculate this condition.
According to the docs, the smoothing condition should be determined in this way:
Recommended values of s depend on the weights, w. If the weights represent the inverse of the standard-deviation of y, then a good s value should be found in the range (m-sqrt(2*m),m+sqrt(2*m)) where m is the number of datapoints in x, y, and w. default : s=m-sqrt(2*m) if weights are supplied. s = 0.0 (interpolating) if no weights are supplied.
However, after much testing, I haven't been able to get this to work (where smoothing is non-zero). The "fit" usually ends up looking like an arbitrary 3rd degree polynomial. I'm dealing with a dataset that should be a high degree polynomial when fit properly. Just from fiddling around with the smoothing condition, I've found s = 1E-9 to balance closeness and smoothing well (I'm using weights with the data).
Does anyone have any ideas what's going on?
There are reasons I'm using a cubic-spline over other interpolation methods, but I'm wondering if I should be looking elsewhere...