1

I try to interpolate some data points generated by a self-defined function. All points should like very similar to a sine curve. When I run

fit_curve = spitpl.interp1d(u,v,kind="cubic")
x=gamma*np.linspace(-3,3,3000)
plt.plot(x,fitcurve(x), 'r-')

sometimes it fails (see the attached figures). I just slightly change a parameter in the function for the two cases, and the generated points just change slightly. They all look pretty well-behaved in a scatter plot, but the interpolating curve will change from a very good fit to a wildly behaving curve. Any ideas why is that? When I just slinear then it works fine, but I want a higher accuracy from cubic spline.

when it is good: enter image description here a zoom-in figure: enter image description here

when it is bad (generated points are slightly different due to a change in function parameter) enter image description here a zoom-in figure enter image description here

Physicist
  • 2,848
  • 8
  • 33
  • 62
  • 3
    Can you create a MCVE (http://stackoverflow.com/help/mcve) that demonstrates the issue? – Warren Weckesser Sep 03 '16 at 14:15
  • From the limited info here, it looks like you might be having an [overfitting](https://en.wikipedia.org/wiki/Overfitting) issue. You might want to try some form of [cross-validation](https://en.wikipedia.org/wiki/Cross-validation_(statistics)). – Praveen Sep 04 '16 at 20:26
  • Do you get the same problem if you scale you data `v` to be in the range (0,1) instead of (0, 1e-8)? It could be a numerical convergence issue... – Ramon Crehuet Sep 07 '16 at 10:50

0 Answers0