shadeless shadeless - 10 months ago 105
Python Question

Python: Redefine maxit in UnivariateSpline

I tried to use SciPy's smoothing univariate spline

from scipy.interpolate import UnivariateSpline
spl = UnivariateSpline(x, y)

And I get this error message.

/usr/lib/python3.5/site-packages/scipy/interpolate/ UserWarning:
The maximal number of iterations maxit (set to 20 by the program)
allowed for finding a smoothing spline with fp=s has been reached: s
too small.
There is an approximation returned but the corresponding weighted sum
of squared residuals does not satisfy the condition abs(fp-s)/s < tol.

How can I redefine the maxit parameter? I haven't been able to find anything in the SciPy manual except that it's a keyword in class scipy.odr.ODR. I haven't had much luck though.

Answer Source

You cannot change this parameter, it's fixed deep down in the FITPACK code:

In principle, you could modify the Fortran sources and recompile scipy, but this is almost surely not what you want to do. Instead, you could use the s parameter of the UnivariateSpline (or splrep, for that matter) to see if you're getting something useful given your data x and y.

And, by the way, ODR has nothing to do with this.