Note that there are some explanatory texts on larger screens.

plurals
  1. POscipy.interpolate.UnivariateSpline not smoothing regardless of parameters
    primarykey
    data
    text
    <p>I'm having trouble getting scipy.interpolate.UnivariateSpline to use any smoothing when interpolating. Based on the <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline" rel="nofollow noreferrer">function's page</a> as well as some <a href="https://stackoverflow.com/questions/7906126/spline-representation-with-scipy-interpolate-poor-interpolation-for-low-amplitu">previous posts</a>, I believe it should provide smoothing with the <code>s</code> parameter.</p> <p>Here is my code:</p> <pre><code># Imports import scipy import pylab # Set up and plot actual data x = [0, 5024.2059124920379, 7933.1645067836089, 7990.4664106277542, 9879.9717114947653, 13738.60563208926, 15113.277958924193] y = [0.0, 3072.5653360000988, 5477.2689107965398, 5851.6866463790966, 6056.3852496014106, 7895.2332350173638, 9154.2956175610598] pylab.plot(x, y, "o", label="Actual") # Plot estimates using splines with a range of degrees for k in range(1, 4): mySpline = scipy.interpolate.UnivariateSpline(x=x, y=y, k=k, s=2) xi = range(0, 15100, 20) yi = mySpline(xi) pylab.plot(xi, yi, label="Predicted k=%d" % k) # Show the plot pylab.grid(True) pylab.xticks(rotation=45) pylab.legend( loc="lower right" ) pylab.show() </code></pre> <p>Here is the result:</p> <p><img src="https://i.stack.imgur.com/dBgLJ.png" alt="Splines without smoothing"></p> <p>I have tried this with a range of <code>s</code> values (0.01, 0.1, 1, 2, 5, 50), as well as explicit weights, set to either the same thing (1.0) or randomized. I still can't get any smoothing, and the number of knots is always the same as the number of data points. In particular, I'm looking for outliers like that 4th point (7990.4664106277542, 5851.6866463790966) to be smoothed over.</p> <p>Is it because I don't have enough data? If so, is there a similar spline function or cluster technique I can apply to achieve smoothing with this few datapoints?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload